lua-users home
lua-l archive

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


> >I'd like to ask if I can specify a table to which add a code which I load
> >from the buffer.
>
> Yes. See http://lua-users.org/lists/lua-l/2003-08/msg00235.html .

    if (luaL_loadfile(L, my_script_file_name))  /* from lauxlib.h */
        lua_error(L);

    /* prepare environment */
    lua_newtable(L);
    /* add some data here ... */

    /* set it as the loaded chunk's environment
       (it will act as the chunk's table of globals) */
    lua_setfenv(L, -2);

    /* run chunk */
    lua_call(L, 0, 0);

but where can I specify the name of the namespace?
I thought code may look like this

create_table(L,"my_namespace");
lua_dofile(L,my_script_file_name);
closetable(L,"my_namespace")
lua_dofile(L,main_script_file_name);

and after this in main_script_file_name I can access the functions defined
in the my_script_file_name as
"my_namespace.function_name(...)"

Best regards,
Dmitriy Iassenev