lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>>>>> "Massimo" == Massimo Sala <massimo.sala.71@gmail.com> writes:

 [luaL_dofile]

 Massimo> 1) return code

 Massimo> The manual says " It returns false if there are no errors or
 Massimo> true in case of errors."

That's "false" and "true" in the C sense, where 0 is false and anything
that's not 0 is true.

i.e. the simplest usage is just

  if (luaL_dofile(L, fn))
  {
    /* failed; do something with the error message that's at the top of
       the Lua stack */
  }

You can check the return value against the LUA_ERR* constants if the
code needs to distinguish between file, syntax and runtime errors.

 Massimo> So it seems to me the return values can - at least - be 0, 1,
 Massimo> 7. Am I right ?

It can be any of the error values.

 Massimo> 2) loading compiled files

 Massimo> luaL_dofile can load plain source code and compiled scripts
 Massimo> (bytecode).

 Massimo> I have to check users don't pass filenames of compiled
 Massimo> scripts.

Then don't use luaL_dofile, instead use luaL_loadfilex, which has a
"mode" parameter. Do _NOT_ attempt to assume that you know what a
compiled file looks like.

-- 
Andrew.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org