luajava

Lua Error Attempt to perform arithmetic on local variable

邮差的信 提交于 2019-12-24 10:04:56
问题 Here is the function calc.lua: function foo(n) return n*2 end Here is my LuaJavaCall L.getGlobal("foo"); L.pushJavaObject(8); int retCode=L.pcall(1,1,0); // nResults)//L.pcall(1, 1,-2); String errstr = L.toString(-1); // Attempt to perform arithmetic on local variable 'n' Update: as indicated below I needed to use L.pushNumber(8.0) instead of L.pushJavaObject() 回答1: Try using L.pushNumber instead of L.pushJavaObject like this: L.getGlobal("foo"); L.pushNumber(8.0); int retCode = L.pcall(1,1,0

Lua Getting Result Back in LuaJava from Lua function call

一笑奈何 提交于 2019-12-11 13:20:27
问题 How does one get the value back from a Lua function call in LuaJava. Lets say I have calc.lua: function foo(n) return n*2 end I call the function in Java as follows: LuaState luaState; this.luaState = LuaStateFactory.newLuaState(); this.luaState.openLibs(); this.luaState.LdoFile("calc.lua"); this.luaState.getGlobal("foo"); this.luaState.pushNumber(5.0); int retcode=this.luaState.pcall(1, 1,0); Now what do I have to call on LuaState object to get the result of this last function call foo(5)?

LuaJava Setting Error Handler for LuaState.pcall(a,b, error_function_index)?

梦想的初衷 提交于 2019-12-10 16:46:47
问题 I am trying to call: LuaState.pcall(num_args,num_returns, error_handler_index). I need to know how to set the error handler for this function. In fact, I think it would be nice it someone showed how to invoke a Lua function and get a numerical result back using LuaJava. This might save a lot of time and questions. I am looking but not finding the signature for the error function, and how to place it at the right point on the LuaState stack. All the Java->Lua examples are either printing a

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

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.

LuaJava Error in Error Handling

我只是一个虾纸丫 提交于 2019-12-02 04:15:43
问题 I am trying to call a simple Lua function from Java using LuaJava. calc.lua: function foo(n) return n*2 end Thats all there is in calc.lua and subsequent calls from command line work. Here is the call that always has error : L.getGlobal("foo"); L.pushNumber(8.0); int retCode=L.pcall(1, 1,-2); // retCode value is always 5 pcall(numArgs,numRet,errHandler) String s = L.toString(-1); // s= "Error in Error Handling Code" I have also tried L.remove(-2); L.insert(-2); Not sure why its giving any

LuaJava Error in Error Handling

懵懂的女人 提交于 2019-12-02 00:37:29
I am trying to call a simple Lua function from Java using LuaJava. calc.lua: function foo(n) return n*2 end Thats all there is in calc.lua and subsequent calls from command line work. Here is the call that always has error : L.getGlobal("foo"); L.pushNumber(8.0); int retCode=L.pcall(1, 1,-2); // retCode value is always 5 pcall(numArgs,numRet,errHandler) String s = L.toString(-1); // s= "Error in Error Handling Code" I have also tried L.remove(-2); L.insert(-2); Not sure why its giving any error at all or what the error is. Maybe I'm not setting up error handler correctly? So it does not make

How Do I Load Lua Module as a String Instead of a File?

早过忘川 提交于 2019-12-01 18:52:30
问题 I am using LuaJava and C Code for Lua. What I am trying to do is read Lua source stored as a resource String in an Android application so that the Lua source read in can be executed. I need to know how to do this using LuaJava or C language. I want to know how I can create a Lua module in Lua by using a String. In other words, I am storing Lua source that would be stored in a .lua file in a String instead. I then want to load the contents of this string into Lua as an available module that