1

Within my code, I need to push an int onto Lua's stack. I know of the lua_pushnumber for C, but what would be used in LuaJ? I can't find a function for it, given that LuaJ isn't clear as to what functions represent certain C functions.

PuppyKevin
  • 2,967
  • 7
  • 25
  • 27

1 Answers1

1

LuaJ abstracts things like stack management away. So if you're trying to call a Lua function, you don't have to push values onto the stack. Just get the Lua function as a LuaFunction variable and call it with the invoke method. To return multiple values from a Java function registered with Lua, you have to return a Varags object. You put your multiple values into that.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I must be doing something wrong. I'm getting a "attempt to index ? (a nil value)" error whenever I try to access the value from within the script. So far, I have it set up like so: In the script, there's a line that reads, "yes = sendYesNo("test");", which get binded with a TwoArgFunction class, which reads the inputted text, sends some data to a client, and sets up a coroutine to wait for the user to send information back to the server. When the info does come back, it gets processed in another class, and this is where I would think that the stack push would be required. Within the... – PuppyKevin Mar 20 '12 at 02:10
  • ...TwoArgFunction class that I set up, it's just returning LuaValue.ONE, despite the error still coming up. What am I doing wrong? – PuppyKevin Mar 20 '12 at 02:11
  • @PuppyKevin: Can you put your actual code (Java and the Lua code) in the post, so that we can understand what you're doing? – Nicol Bolas Mar 20 '12 at 02:13
  • Actually, I found out what the issue was. Directly after the "yes = sendYesNo("test");" line, I had "print(yes);". After commenting it out, everything works as it should be. Any reason as to why I can't print out a value like that, and which method I'd have to take to print it out? – PuppyKevin Mar 20 '12 at 02:48