How to get results from a Delphi function called by Lua -
i creating function in delphi able use lua. have managed create procedure (or function without taking results) , works perfect. problem want results of function (not procedure anymore) delphi lua. i've read codes out there couldn't make work.
my function looks this:
function tluascripter.getsetting(luastate: tluastate):tluastate; var path,stri: string; i:integer; begin //getsetting('targeting/targetingenabled') path := lua_tostring(luastate, 1); //we string 'targeting/..." lua_pop(luastate,1); //we put in stack (so can clean it) stri:= tree.getsetting(path); //this function gets, example "no" lua_pushlstring(luastate,pansichar(ansistring(stri)),length(stri)); //i pass lua stack //showmessage(lua_tostring(luastate,1));--> shows result need in msgbox result:= luastate; end;
so if use in lua console
getsetting('targeting/targetingenabled')
i able result in msgbox (uncommenting "showmessage...") function doesn't return in lua! if write
print(getsetting('targeting/targetingenabled'))
i nil value in lua.
it work perfect this. have added result integer , "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;
Comments
Post a Comment