lua-users home
lua-l archive

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

Użytkownik Luiz Henrique de Figueiredo napisał:

>   * lua_newuserdata() is not what I need, because I already have
>     allocated memory...


If you need uniqueness,
then create a weak table indexed by your C pointers with values equal to the corresponding userdata and only call lua_newuserdata or lua_boxpointer if the pointer is not in the table. Note, a WEAK table is needed, otherwise the value
will never be GC'd.

Thanks, I'll try this... :-)
I did not expect that I will ever need to use weak references..

But.. I have one more question.
(I have tried to find answer in archives but without success)

Lua-4 had simple API with two functions newuserdata and pushusertag, lua-5 have now only newuserdata. Why this? In my (maybe stupid) opinion it does not conform to KISS rule. This implementation is limited only to using malloced memory (no mmap, no shared memory, etc).

Im just courious...

Best regards,
Andrzej Borsuk

    (;[   SPAM?
   \/>)   Proszę wysyłać na moje podstawowe konto
  `ab~^   mailto:root@localhost