lua-users home
lua-l archive

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


On 5 July 2012 21:54, liam mail <liam.list@googlemail.com> wrote:
> This topic was brought up by Ca11um in IRC.
> Basically is it correct that instead of calling luaL_openlibs to call
> the luaopen_* functions separately (I notice they are not listed in
> the manual)?
>
> The following minimal code does not set the modules.( OOLUA::run_chunk
> just runs the chunk checking for error etc it is not important.)
>
> void foo (  )
> {
>         lua_State* lua = luaL_newstate();
>
> //      luaL_openlibs(lua);
>         luaopen_base ( lua );
>         luaopen_package(lua);
>         luaopen_coroutine( lua );
>         luaopen_table ( lua );
>         luaopen_io(lua);
>         luaopen_os(lua);
>         luaopen_string ( lua );
>         luaopen_bit32( lua );
>         luaopen_math ( lua );
>         luaopen_debug ( lua );
>         if( ! OOLUA::run_chunk(lua,"for k,v in pairs(_ENV)do print(k,v) end") )
>         {
>                 std::cout <<OOLUA::get_last_error(lua);
>         }
> }
>
> The output is:
> setmetatable    function: 0x10004f489
> collectgarbage  function: 0x10004f6ad
> tostring        function: 0x1000500c5
> loadfile        function: 0x10004fa45
> unpack  function: 0x10006d52c
> require function: 0x1010476c0
> module  function: 0x101047690
> _VERSION        Lua 5.2
> dofile  function: 0x10004fd2c
> _G      table: 0x10103d2b0
> xpcall  function: 0x10005001c
> type    function: 0x10004f7b5
> rawget  function: 0x10004f5f3
> next    function: 0x10004f8bb
> select  function: 0x10004fe20
> tonumber        function: 0x10004f064
> ipairs  function: 0x10004f9ce
> assert  function: 0x10004fdb4
> rawset  function: 0x10004f649
> pairs   function: 0x10004f91e
> loadstring      function: 0x10004fbd9
> rawlen  function: 0x10004f58e
> getmetatable    function: 0x10004f424
> error   function: 0x10004f3a3
> load    function: 0x10004fbd9
> print   function: 0x10004ef1c
> rawequal        function: 0x10004f53b
> pcall   function: 0x10004ff9e

http://www.lua.org/manual/5.2/manual.html#6

To have access to these libraries, the C host program should call the
luaL_openlibs function, which opens all standard libraries.
Alternatively, the host program can open them individually by using
luaL_requiref to call luaopen_base (for the basic library),
luaopen_package (for the package library), luaopen_coroutine (for the
coroutine library), luaopen_string (for the string library),
luaopen_table (for the table library), luaopen_math (for the
mathematical library), luaopen_bit32 (for the bit library), luaopen_io
(for the I/O library), luaopen_os (for the Operating System library),
and luaopen_debug (for the debug library). These functions are
declared in lualib.h.

Liam