procedure LuaTimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);stdcall;
var
i:integer;
id:UINT;
LuaState: TLuaState;
begin
killtimer(hwnd,idEvent);
for i:=(LuaTimerList.Count div 2) -1 downto 0 do begin
id:=UINT(LuaTimerList.Items[i*2+1]);
if id=idEvent then begin
LuaState:=TLuaState(LuaTimerList[i*2]);
LuaTimerList.Delete(i*2+1);
LuaTimerList.Delete(i*2);
lua_resume(LuaState,0);
end;
end;
end;
function TTestLua.delay(LuaState: TLuaState): Integer;
var
milliseconds:integer;
id:integer;
begin
if Lua_Gettop(LuaState)=0 then exit;
milliseconds := Lua_ToInteger(LuaState,1);
id := settimer(0,0,milliseconds,@LuaTimerProc);
if LuaTimerList=nil then LuaTimerList := TList.create;