Jump to content

Image of the Day

#QuestOfDungeons is an old-fashioned dungeon crawler. #ScreenshotSaturday  #PS4share

https://t.co/1mztLegxeN https://t.co/DpYimg3MZb
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

Importing Lua functions into Java with LuaJ.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 PuppyKevin   Members   

103
Like
0Likes
Like

Posted 29 June 2012 - 07:12 PM

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?

#2 Kyan   Members   

395
Like
0Likes
Like

Posted 29 June 2012 - 11:11 PM

Depends on how you're using the API. Straight from the example in the Javadocs, you'd do something like:
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 );
It looks like LuaValue 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 call on it with the arguments you wish to pass.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.