Sign in to follow this  

Importing Lua functions into Java with LuaJ.

This topic is 1995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I have a Lua file filled with a couple of functions, and I'm using LuaJ to execute these scripts via Java. I'm able to get Java functions to work within Lua, but how would I call a Lua function from Java?

Share this post


Link to post
Share on other sites
Depends on how you're using the API. Straight from the example in the Javadocs, you'd do something like:
[CODE]
LuaValue globals = JsePlatform.standardGlobals();
LuaValue sqrt = globals.get("math").get("sqrt");
LuaValue print = globals.get("print");
LuaValue d = sqrt.call( a );
print.call( LuaValue.valueOf("sqrt(5):"), a );
[/CODE]
It looks like [i]LuaValue[/i] is your transport to the Lua layer - it contains most of the overloads you'd need. You grab the function you want and then execute a [i]call[/i] on it with the arguments you wish to pass.

Share this post


Link to post
Share on other sites

This topic is 1995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this