Library loading error messages (was: Trouble building/loading shared libraries)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Library loading error messages (was: Trouble building/loading shared libraries)

Paul Chiusano
Yes, I am a dummy - I had the library in both package.path and
package.cpath.  When it found it in package.path, I'm assuming it
tried to load it as lua code, and was confused when the file was
actually binary. Thanks for the help. It is working now! :-)

Would it be possible to improve the error message of 'unexpected
symbol near...' in these cases?

For instance, one thing I could think of is: if require gets an
'unexpected symbol' and the file being loaded has a '.so' or '.bundle'
or '.dll' extension, (or perhaps just any non .lua extension), it
appends a more friendly reminder, something like:

lua: error loading module 'numvector' from file '':
       ' unexpected symbol near '�': This may be the
result of attempting to load a binary library as Lua code. C shared
libraries should appear in package.cpath, not package.path.

Or something like that. Also, this might just be me, but I didn't
immediately get my problem from looking at the docs for require ( ). What would
have been totally clear (for me, anyway) is something like:

require (modname)

Loads the given module. The function starts by looking into the table
package.loaded to determine whether modname is already loaded. If it
is, then require returns the value stored at package.loaded[modname].
Otherwise, it tries to match the required name to a location in either
package.path or package.cpath.

If the required name is matched to a location in package.path, it is
assumed to be Lua code and will be loaded by <details of how lua code
is loaded: a call to dofile?>. If the required name is matched to a
location found in package.cpath, it is assumed to be a C shared
library and is loaded in the following way:

<same as before: load using dynamic linking, then look for
luaopen_packageName, etc>

Lua authors, if you don't think I am bonkers for not getting this from
the current docs, let me know and I'd be happy to try to write
something more complete and polished than the above.


> Check if your .so is located at the package.cpath and not package.path.
> Probably, you are trying to load a c module instead of a Lua script file.
> --rb

> Have your module embedded lua code  in plain or precompiled format ?.
> Please review as they are being loaded, or verifies that the carriage
> returns are according to their platform.