lua-users home
lua-l archive

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


As I try to learn how to embed and extend lua into/with my program
I found some lack of information in reference manual (or I see
them as such).

For opening standard libraries there is function
luaL_openlibs()
which is clear enough. But if I want to open only some
(not all) library it is mentioned I need to use eg.
luaopen_math by calling them with lua_call function.
On the internet I found this snippet
        lua_pushcfunction(L, luaopen_math);
        lua_pushstring(L, LUA_MATHLIBNAME);
        lua_call(L, 1, 0);
and it works in my program. But from reference manual it is not
clear that luaopen_xxx function need any argument (LUA_XXXLIBNAME)
and that this argument is string. From reference manual I could
not extract enough information to correctly open individual
library. Also only after investigating linic.c in lua source
I found that argument LUA_XXXLIBNAME for luaopen_xxx is not
in 1:1 relation with name of library. Here is copy from linit.c
that shows which library needs which argument:
  {LUA_LOADLIBNAME, luaopen_package},
  {LUA_TABLIBNAME, luaopen_table},
  {LUA_IOLIBNAME, luaopen_io},
  {LUA_OSLIBNAME, luaopen_os},
  {LUA_STRLIBNAME, luaopen_string},
  {LUA_MATHLIBNAME, luaopen_math},
  {LUA_DBLIBNAME, luaopen_debug},
 
In description of string module maybe there should be explicitly noted
that string.byte string.char string.len (perhaps other functions too)
works intuitively only with ASCII encoding. With utf-8 encoding
that I have set on my computer results are strange. I do not know how
they work under Windows Unicode charset.

It is not emphasized that print() function interpret its
argument as c string. Namely if supplied argument contains
\0 in string (string.byte(c) == 0) only portion before zero
is printed. There could be also noted that print() automatically
adds newline at the end of its argument list.

Also as it was mentioned in some other thread I would welcome
explicit note in reference manual that % (modulo) operator and
math.fmod() function produce different results (albeit both are
correct).

Martin