lua-users home
lua-l archive

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


Diego Nehab wrote:
For lua_tonumber, this seems easy to do. But for
lua_tostring, where would the returned string be? It has to
be allocated somewhere, and it has to be collected at some
point, but only after the object you are calling it on
leaves the stack.

Well, another option would be to return a copy of the string that the user has the responsibility to free().

That would allow lua_tostring() to be implemented as expected, that is, it could return a string without changing numbers in the stack.

This approach would make the API simple and clear, at the cost of complicating the user code (call to free() needed). Further thinking about it, taking Windows DLL issues into account, in fact another Lua API function like e.g. lua_freestring(const char* s) would be needed. Even though this method would in turn just call free(s);, the user had to call this method instead of free() in order to make sure that it works without heap corruption even if Lua is compiled into a DLL.


Ca3D - Engine
Carsten Fuchs