lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
>> And ... IMHO mutable strings probably won't have less management
>> overhead than buffers implemented with userdatas. Yes, I know,
>> passing userdatas to C APIs expecting plain strings doesn't work
>> right now. But this can be changed.
> This seems a more promissing approach. Diego suggested something in
> these lines some time ago. (Of course, the userdata must be converted
> to a char*, not to a Lua string; this is tricky with metamethods...)  

It could be possible to override lua_istring, lua_tostring and
lua_pushstring to accept/generate such string userdata (which would be
identified with a __isstring boolean metamember). That way many binary
modules designed for non-mutable strings could work transparently with
mutable ones.

For the lua_tostring it's straightforward, for lua_pushstring it may be
desirable to activate it on a per function basis (which could have a
__pushmutablestrings boolean member in the function metatable) by the
module user.