WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
391 stars 30 forks source link

call_function can't return value #19

Closed cenullum closed 3 years ago

cenullum commented 3 years ago

Is your feature request related to a problem? Please describe. I think call_function can't return values yet.

Describe the solution you'd like

if(lua.lua_function_exists("LuaFunctionName") ):
     var value = lua.call_function( "LuaFunctionName",[])
print(value)
function LuaFunctionName()
     return "Hello from lua"
end
Trey2k commented 3 years ago

This is correct, currently call_function will not return a value. Should be a easy fix.

Trey2k commented 3 years ago

Okay I think this is probably the best way to support it. It will always return a Variant now. If lua returns nothing the Variants value will be null. Checkout the dev branch https://github.com/Trey2k/lua/tree/dev

Trey2k commented 3 years ago

Added in 1ff4f705ce9a8eace1afb232668b9532d01961f6. Expect it in the next minor release

cenullum commented 3 years ago

Something is wrong I created a project for you to see too "stats" value stay as 123 which is initial value Test.zip you can drag and drop the lua file and press f9 to increase test value, in lua it adds test to stats value

Trey2k commented 3 years ago

Something is wrong I created a project for you to see too "stats" value stay as 123 which is initial value Test.zip you can drag and drop the lua file and press f9 to increase test value, in lua it adds test to stats value

Silly bug haha, I forgot to pop the return value off the stack. So in a since it cached the initial value. Fixed it dev branch