lua-users home
lua-l archive

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

> There are two changes I'd like to see in Lua, both of which would make
> it a little easier to connect C code to Lua.
> I try to be careful in my code to use const char * when I know I'm
> dealing with immutable strings.  Unfortunately, many Lua functions use
> parameter types of char *, even when const char * would be correct, so
> I get a slew of warning messages.  It would be nice if the signatures
> were updated properly.  I believe that *all* strings are immutable in
> Lua, so that all instances of char * could be replaced with const
> char*.

In fact, all strings in Lua are immutable, and the addition of "const" 
could make things clearer. But that change is not that easy; we would have 
to change all Lua to use "const", otherwise we sould only change the 
position of the warnings. Besides the work, this has two difficulties: 

- some machines do not have correct "const"s in their header files; when
we use const on those machines we get a lot of warnings when calling strcmp,
strcpy, etc.

- once we changed all Lua to use const. I know this is unbelievable, but in
our machine this change made Lua bigger and slower (we double-checked that)!!
After that we gave up using const.

  For now, you may use some macros to do a "polite" typecast from "const
char *" to "char *" around Lua API.

> The other change I'd like to see is minor: I'd like the C version of
> lua_error to have the same signature as printf.  This should
> relatively easy to implement in ANSI C using <stdarg.h> and vsprintf.

Unfortunately, this is not a minor change. The error method is a Lua 
function, not a C one. When you call lua_error, the error method is called 
through Lua calling conventions, and there is no way in ANSI C to 
dynamically build the "arg list" from Lua parameters. On the other hand, we 
cannot use Lua's "format" in the default error method, because "format" is 
not part of Lua: It's in a library. 

-- Roberto