Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The likely problem is that <a href="http://www.lua.org/manual/5.1/manual.html#luaL_loadfile" rel="nofollow noreferrer"><code>luaL_loadfile()</code></a> is documented to return the same values as <a href="http://www.lua.org/manual/5.1/manual.html#lua_load" rel="nofollow noreferrer"><code>lua_load()</code></a> or one additional error code. In either case, the return value is an <code>int</code> where 0 means success and a nonzero value is an error code.</p> <p>So, the test <code>luaL_loadfile(...) == NULL</code> is <strong>true</strong> if the file was loaded, but the code calls that an error and returns.</p> <p>The function <code>lua_pcall()</code> also returns a status code, and you may want to verify that as well. </p> <p>Otherwise, the script as shown does create a global variable, and <code>lua_getglobal()</code> would retrieve that to the stack where it could be tested with <code>lua_isstring()</code>, or probably more usefully let you return its value if it is sufficiently string-like with <a href="http://www.lua.org/manual/5.1/manual.html#lua_tostring" rel="nofollow noreferrer"><code>lua_tostring()</code></a>. The latter function will return either a <code>const char *</code> pointing at a nul-terminated string, or NULL if the value at the stack index can't be converted to a string. See the Lua reference manual as linked for the rest of the details and a caveat about using <code>lua_tostring()</code> inside a loop.</p> <p><strong>Edit:</strong> I added better links to the manual in a couple of places.</p>
 

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