Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I have a custom function stop a Lua script in Delphi without exiting the application?
    primarykey
    data
    text
    <p>I have an application that periodically will run a Lua script. Within the script, on occasion, I have created a custom registered Lua function to check some parameters and decide if the Lua script should continue or exit. The logic ideally should not be part of the script and I can think of using a Lua script to work around this, but I'm wondering if it is possible to stop the execution of a Lua script without ending the application.</p> <p>I have a custom function written in Delphi and exposed to Lua scripts using Lua 5.1. The Lua script looks something like that shown below and the script in Lua is started using <code>luaL_loadbuffer</code>. </p> <pre><code>io.write("Script starting\n"); --Custom Function ExitIfFound(); io.write("Script continuing\n"); </code></pre> <p>My custom function looks something like this, below I have provided one of my attempts where I tried to use <code>lua_error</code> to stop the script...</p> <pre class="lang-pascal prettyprint-override"><code>function ExitIfFound(LuaState: TLuaState): Integer; var s: AnsiString; begin s := 'ExitIfFound ending script, next Lua script line not called'; lua_pushstring(LuaState, PAnsiString(s)); lua_error(LuaState); end; </code></pre> <p>When my custom function is called, I'm unsure as to how to exit the Lua script without any further evaluation. I have seen posts referring to Lua and using <code>setjmp</code> and <code>longjmp</code> in C, but I'm curious how these may translate Delphi.</p> <p>In the example above, when I use <code>lua_error</code>, the entire program crashes with Windows doing its typical, <code>[luarun.exe has stopped working]</code> ...</p> <p>With all of this, I'm am still pretty new to integrating Lua to Delphi and hoping that I can find some cleaner options to explore.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload