|
|

楼主 |
发表于 2006-7-1 11:40:00
|
显示全部楼层
Re:请教Delphi执行Lua函数的问题,谢谢
已想到办法解决,以下为解决办法,以提参考
TestABC.Lua的内容如下
TempValue = nil
function Add(x, y)
return x + y
end
function GetValue
return TempValue
end
delphi的代码就改为如下,就可以获得Add的返回值了
procedure TForm1.Button1Click(Sender: TObject);
var
l: p_lua_state;
Temp : String;
begin
l := lua_open();
lua_baselibopen(l);
lua_dofile(l, 'Test.Lua');
lua_dostring(l, 'TempValue = add(10, 10)');
lua_getglobal(L, 'GetValue');
lua_call(L, 0, 1);
Temp := string(lua_tostring(l, -1));
lua_close(l);
ShowMessage(Temp);
end; |
|