lua-users home
lua-l archive

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


2012/10/2  <andre@leiradella.com>:
> 1. Is there a better way to handle a C/Lua mixed module? I don't need anything fancy, just register Lua and C functions.

As other mentionned you can split your code into 2 modules, but it has
its drawbacks.

> 2. Can/should I call lua_error in luaopen_task if one of the functions I call fails?

If you stick to the single approach, just printing an error message
and returning 0 is not a correct module implementation, since
'require' will assume that the loading succeeded (it will put true in
'package.loaded' and return that). If loading fails you should throw
an error, but rather than catching the Lua code error and throwing
another one, it's simpler and maybe cleaner to just let the Lua error
propagate. For that you need to replace your lua_pcall with a
lua_call, and make sure that your loader function is leak-proof if the
lua_call don't return (it looks like it is, but your actual code may
be different from what you posted).