我在Delphi中创建了一个能够与Lua一起使用的函数.我已经设法创建一个过程(或一个没有取得结果的函数),它完美无缺.问题是,现在我想从Delphi到Lua获得该函数的结果(不再是程序).我已经阅读了一些代码,但无法使其正常工作.
我的功能看起来像这样:
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;
Run Code Online (Sandbox Code Playgroud)
所以现在如果我在我的Lua控制台中使用
getsetting('Targeting/TargetingEnabled')
Run Code Online (Sandbox Code Playgroud)
我能够在msgbox中获得结果(取消注释"Showmessage ..."),但该函数不会返回Lua中的任何内容!如果我写
print(getsetting('Targeting/TargetingEnabled'))
Run Code Online (Sandbox Code Playgroud)
我在Lua得到一个零值.
我期待使用像"asdf"这样的变量,而不是编写名称函数来检查它的返回(它会不时变化).这就是为什么"asdf"变量应该在我们每次使用(调用)它时更新它的值
请问在Lua有什么办法吗?
asdf == getFunction() --we define it here
(...) --some code
if asdf < 10 then ... --here we call the variable (so it should get/update again the result of getFunction())
Run Code Online (Sandbox Code Playgroud)
谢谢
我在Delphi中有一个代码,它执行以下操作:
procedure THilo.Execute; // (which is the thread)
begin
inherited;
FreeOnTerminate := True;
while not Terminated do
begin
(...)
Sleep(100);
end;
end;
Run Code Online (Sandbox Code Playgroud)
现在在其他地方,在另一个线程(或GUI)中我们这样做:
var
Hilo2: THilo;
begin
Hilo2 := THilo.Create(True);
Hilo2.start;
Hilo2 := THilo.Create(True);
Hilo2.start;
end;
Run Code Online (Sandbox Code Playgroud)
现在我们已经执行了相同线程的2次,并且它们并行运行.如果我们现在这样做会怎么样?:
Hilo2.Terminate;
Run Code Online (Sandbox Code Playgroud)
这将终止两个线程或只是1,或什么?另外,如果我们想终止它,我们可以通过.Resume()来实现吗?
提前致谢