There is a program code
function GetStatck():TList<TCallStack>; var Level : integer; ar : Plua_Debug; CallStack : TCallStack; begin ..... Result := TList<TCallStack>.Create; ..... Level := 1; .... // Почему при попытке заполнить запись ar данными из стека, постоянно получаем 0 ? while lua_getstack(L, Level, @ar) = 1 do begin .... // СЮДА НЕ ПОПАДАЕМ .... CallStack := TCallStack.Create; .... Result.Add(CallStack); .... end; .... end;
and the code of the main program, for example:
....
procedure TFormMain.DoLua(); var ListCallStack: TList<TCallStack>; begin Lua.DoString('print "Hello World"'); .... // Тут хотелось бы увидеть результат, получить список данных ListCallStack := GetStatck(); .... end;
How to get Traceback using the lua_getstack function?
Here is a simple example of using LUA to get TraceBack - for HelloWorld
procedure TFormMain.DoLua(); ..... Lua.DoString( 'print "Hello World"' + #13#10 + 'print (debug.traceback());'
Result:
hello stack traceback: [string "print" Hello World "..."]: 2: in main chunk
Help solve the problem, what's the problem? why let's say as an example executing such a code, the stack data is also visible ...:
function low () mid() end function mid() high(5) end function high(val) print (debug.traceback()) end print ("Started") low() print ("Completed")
I use Delphi 10 and wrapper for LUA (VerySimple) - http://blog.spreendigital.de/2015/02/18/verysimple-lua-2-0-a-cross-platform-lua-5-3-0-wrapper -for-delphi-xe5-xe7 /
print "Hello World"
? The stack, in general, stores local variables of functions, return addresses from them, and what you yourself put there. What of this is present in your first program? In the second, it is clear that at the time of calling thedebug.traceback()
there will be three return addresses. - AlekcvpLevel := 0;
? - zedlua_getstack
it says: “it receives information about the runtime stack,” that is, as I understand it, it is intended to be called in hooks. You try to call it after the end of the program, but this is not runtime. - Alekcvp