小编use*_*704的帖子

如何从Lua调用的Delphi函数中获得结果

我在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得到一个零值.

delphi lua return

5
推荐指数
1
解决办法
787
查看次数

仅通过写一个名字来调用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)

谢谢

variables lua function

5
推荐指数
1
解决办法
1705
查看次数

当你终止()一个线程(类TThread)时,它是否会退出该线程的每个子节点?

我在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()来实现吗?

提前致谢

delphi resume multithreading terminate

5
推荐指数
1
解决办法
669
查看次数

标签 统计

delphi ×2

lua ×2

function ×1

multithreading ×1

resume ×1

return ×1

terminate ×1

variables ×1