1

Im calling a function in lua from actionscript using callstack : Array = luaAlchemyInstance.doString("luafunction");

my function should return some values

function luafunction()
return true, 125
end

When i look at the callstack array returned by the function in as3, I recieve only the success/ fail part. The array length is 1, true, and contains none of my return values.

Any idea whats going wrong? Cheers

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
serenskye
  • 3,467
  • 5
  • 35
  • 51

3 Answers3

1

I don't know lua-alchemy, but if doString() follows the same semantics as in standard Lua, the proper way to call the function should be:

callstack : Array = luaAlchemyInstance.doString("return luafunction()");
Michal Kottman
  • 16,375
  • 3
  • 47
  • 62
1

doString() returns array of the values, returned by a call. First item of that array is true or false, indicating call success or failure. If it is false, second item is the error message.

Also note that doString() takes actual Lua code as an argument, so it should be

doString("return luafunction()")

See documentation and example.

Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
-2

I've only ever seen functions in Actionscript that return a single variable type at a time (Number, String, Boolean, etc).

It looks like you are trying to return a Boolean and a Number/int/uint value at the same time.

You could just try to return both as object values, something like this:

function luafunction():Object
{
var obj:Object = new Object();
obj.myBoolean = true;
obj.myNumber = 125;
return obj;
}

Then you can retrieve your values by something like:

trace(obj.myBoolean, obj.myNumber);
redconservatory
  • 21,438
  • 40
  • 120
  • 189