lua-users home
lua-l archive

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

> 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. [...]

Actually, you do not have to pass this parameter to open the standard
libraries. 'require' passes this parameter and some other libraries may
need it; so, for politeness, linit.c does that too. But all standard
libraries work fine without this parameter.

> 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.

We will add a note about that.

> 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.

As 'print' is for quick-and-dirty printing, we prefer not to specify
too many details of its behavior. (If your program depends on these
details, do not use 'print'.)

> 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).

We will specify that 'fmod' "Returns the remainder of the division of
'x' by 'y' that rounds the quotient towards zero." (Modulo '%' already
says that it rounds toward minus infinity.)

Thanks for the feedback,

-- Roberto