lua-users home
lua-l archive

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


Hi,

Comment in loadlib.c:

/*
** Try to find a load function for module 'modname' at file 'filename'.
** First, change '.' to '_' in 'modname'; then, if 'modname' has
** the form X-Y (that is, it has an "ignore mark"), build a function
** name "luaopen_X" and look for it. (For compatibility, if that
** fails, it also tries "luaopen_Y".) If there is no ignore mark,
** look for a function named "luaopen_modname".
*/

So it would try luaopen_GLV and if that fails luaopen_1_getuser.

It looks like putting a hyphen in a directory name may cause confusion.





On Thu, Sep 12, 2019 at 2:26 PM Sean Conner <sean@conman.org> wrote:

  I'm working on a project, using Lua 5.3, and for reasons, all the project
specific modules live under the namespace of "GLV-1".  So far, the modules
written in Lua all load fine, but I do need one written in C.  The Lua
manual states this about a '-' in the filename:

        The fifth line is a mark to ignore all text after it when building
        the luaopen_ function name. Default is '-'.

  Okay.  Testing this out ...

        int luaopen_GLV_getuser(lua_State *L)
        {
          lua_pushboolean(L,1);
          return 1;
        }

I get:

GenericUnixPrompt> lua
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> getuser = require "GLV-1.getuser"
error loading module 'GLV-1.getuser' from file './GLV-1/getuser.so':
        ./GLV-1/getuser.so: undefined symbol: luaopen_1_getuser stack traceback:
        [C]: in ?
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: in ?

  What?  Checking Lua 5.2, I read:

        The fifth line is a mark to ignore all text before it when building
        the luaopen_ function name. Default is '-'.

  So, is the behavior of Lua 5.3 wrong?  Or is the manual wrong?  I mean,
this:

        int luaopen_1_getuser(lua_State *L)
        {
          lua_pushboolean(L,1);
          return 1;
        }

works:
GenericUnixPrompt> lua
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> getuser = require "GLV-1.getuser"

  -spc (Just curious really ... )




--