Archive 17/01/2023.

Getting return values from LuaFunction::EndCall?

Lys0gen

Hey there,
in the documentation of LuaFunction::EndCall it says

bool EndCall (int numReturns=0)
End call and actually execute the function. The return values, if any, are still left in the stack when this call returns.

But I don’t really see any way to retrieve these values from the stack. Neither with LuaFunction nor LuaScriptInstance.
Was this just never implemented? I could get a return value by writing into a passed parameter, but I’m wondering if the proper way is possible as well.

SirNate0

You can retrieve it from the lua_state:

https://www.lua.org/pil/24.2.2.html

You can get the Lua state using LuaScript::GetState

Lys0gen

Thanks! So Urho3D just doesn’t have an abstraction implemented for this and I have to work with the raw interface, got it.

E.g. like this after EndCall.

double retNum = lua_tonumber(scriptSystem->GetState(), -1);
lua_pop(scriptSystem->GetState(), 1);