I am creating a function in Delphi to be able to use it with Lua. I have managed to create a procedure (or a function without taking results) and it works perfect. The problem is that now I want to get results of that function (not a procedure anymore) from Delphi into Lua. I've read some codes out there but couldn't make it work.
My function looks like this:
function TLuaScripter.getsetting(LuaState: TLuaState):TluaState;
var
path,stri: string; i:integer;
begin //getsetting('Targeting/TargetingEnabled')
path := Lua_ToString(LuaState, 1); //we get the string 'Targeting/..."
Lua_Pop(LuaState,1); //we put it in stack (so we can clean it)
stri:= tree.GETsetting(path); //this function gets, for example "No"
lua_pushlstring(LuaState,Pansichar(ansistring(stri)),length(stri)); //I pass it to the lua stack
//showmessage(Lua_ToString(LuaState,1));--> this shows the result I need in a msgbox
result:= LuaState;
end;
so now if I use in my Lua Console
getsetting('Targeting/TargetingEnabled')
I am able to get the result in a msgbox (uncommenting the "Showmessage...") but that function doesn't return anything in Lua! If I write
print(getsetting('Targeting/TargetingEnabled'))
I get a Nil value in Lua.
It will work perfect with this. We have just added the result as integer and "result:=1"
function TLuaScripter.getsetting(LuaState: TLuaState): integer;
var
path,stri: string;
i: integer;
begin //getsetting('Targeting/TargetingEnabled')
path := Lua_ToString(LuaState, 1);
stri:= tree.GETsetting(path);
lua_pushlstring(LuaState,Pansichar(ansistring(stri)),length(stri));
result:= 1;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With