luaj

LuaJ Import Lua Methods

十年热恋 提交于 2019-12-08 02:51:33
问题 I'm using LuaJ, and I have a .lua file filled with a bunch of functions. How do I import these functions to use in Java with LuaJ? 回答1: One option would be to compile the file into Java code and import that. Another would be to simply invoke the Lua file directly from your Java code using the embeddable interpreter. * EDIT * There are good examples in the downloaded documentation. To run a script from within Java you would do something like this: import java.io.File; import java.io.FileReader

Requiring other lua scripts from within a Lua script using LuaJ on Android

坚强是说给别人听的谎言 提交于 2019-12-07 18:48:35
问题 I'm having trouble calling Lua scripts from Java via LuaJ on Android that require other Lua scripts. I think it's something to do with my current working directory. What I'm trying in Java: InputStream input = EvilApp.getContext().getAssets().open("lua/pathTest.lua"); Prototype p = LuaC.instance.compile(input, "pathTest.lua"); LuaValue g = JsePlatform.standardGlobals(); LuaClosure c = new LuaClosure(p, g); c.call(); pathTest.lua: require "Foo" local str = Foo.getString() print(str) For this

Open Arrays or ArrayLists in Lua (Convert array to table)

↘锁芯ラ 提交于 2019-12-06 14:51:40
问题 A method in java returns an Array, and I want to manipulate the information from that array in Lua but it seems that Lua doesn't convert arrays to tables as I'd hoped. Is there a way to do this? For example I have this method in Java: public Node[] getChildren(){ return children.toArray(new Node[children.size()]); } When I call this function from Lua I can't do anything with it or have to Instance it, iterate trough it and copy everything to a Lua-Table and then use it. Is there a way to

LuaJ Import Lua Methods

不羁岁月 提交于 2019-12-06 10:24:22
I'm using LuaJ, and I have a .lua file filled with a bunch of functions. How do I import these functions to use in Java with LuaJ? One option would be to compile the file into Java code and import that. Another would be to simply invoke the Lua file directly from your Java code using the embeddable interpreter. * EDIT * There are good examples in the downloaded documentation. To run a script from within Java you would do something like this: import java.io.File; import java.io.FileReader; import java.io.Reader; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public

Is it possible to execute a single lua statement from a host program?

无人久伴 提交于 2019-12-06 02:47:45
问题 I am trying to embed a lua-based script system into my game engine. I would like the scripting to be able to have both blocking and non-blocking commands, for example: character.walkTo(24, 359); // Blocks until character arrives c = 35; // Non blocking, execution goes on to the next statement Since the "walkTo" needs to be "active" for more than 1 frame of execution, I would like to be able to run 1 statement at time from the Java host instead of the whole function. This is because it would

Lua / Java / LuaJ - Handling or Interrupting Infinite Loops and Threads

帅比萌擦擦* 提交于 2019-12-05 18:54:31
I'm using LuaJ to run user-created Lua scripts in Java. However, running a Lua script that never returns causes the Java thread to freeze. This also renders the thread uninterruptible. I run the Lua script with: JsePlatform.standardGlobals().loadFile("badscript.lua").call(); badscript.lua contains while true do end . I'd like to be able to automatically terminate scripts which are stuck in unyielding loops and also allow users to manually terminate their Lua scripts while they are running. I've read about debug.sethook and pcall , though I'm not sure how I'd properly use them for my purposes.

Open Arrays or ArrayLists in Lua (Convert array to table)

你离开我真会死。 提交于 2019-12-04 22:23:28
A method in java returns an Array, and I want to manipulate the information from that array in Lua but it seems that Lua doesn't convert arrays to tables as I'd hoped. Is there a way to do this? For example I have this method in Java: public Node[] getChildren(){ return children.toArray(new Node[children.size()]); } When I call this function from Lua I can't do anything with it or have to Instance it, iterate trough it and copy everything to a Lua-Table and then use it. Is there a way to convert the Array to a Lua-Table in Java and then return that? EDIT: I use LuaJ and the LuaJava library.

Is it possible to execute a single lua statement from a host program?

北城余情 提交于 2019-12-04 07:51:54
I am trying to embed a lua-based script system into my game engine. I would like the scripting to be able to have both blocking and non-blocking commands, for example: character.walkTo(24, 359); // Blocks until character arrives c = 35; // Non blocking, execution goes on to the next statement Since the "walkTo" needs to be "active" for more than 1 frame of execution, I would like to be able to run 1 statement at time from the Java host instead of the whole function. This is because it would be overkill to have real multithreading, which is not needed. If I could execute just 1 statement, and

How can I pass objects to an exposed luaj function?

℡╲_俬逩灬. 提交于 2019-11-30 19:13:09
I am trying to build a controller using Luaj + java. I have the following java classes public class Duck { public void talk() { System.out.println("Duck quacks!"); } public void walk() { System.out.println("Duck walks!"); } } public class Person { public void talk() { System.out.println("Person talks!"); } public void walk() { System.out.println("Person walks!"); } } and the following lua script for the controller: onTalk(obj) obj:talk(); end onWalk(obj) obj:walk(); end I would ideally like to define one controller (written in lua) where I will keep all of the program's logic, and I would like