lua-users home
lua-l archive

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


Asko:
I am sending you the luapi tarball for the 5.0-alpha release. I had no time
to check if it works
with 5.0-beta, and, checking the doc, I see it is very imcomplete.
Regarding userdata, I recommend you to see
a) the ud*.lua scripts
b) the udtest.c module ( which must be linked to host.o, if you like to
build it )
c) the related functions in luapi.c ( they are all at the end of the
module ).
Some time in the next days, I will ´port´ luapi to 5.0-beta.
Marcelo
PS as you can see, userdata is a powerful concept/construct. They can
approach C++ power.
So I am intrigued regarding a full ´overloaded´ treatment in lvm.


----- Original Message -----
From: "Asko Kauppi" <Asko.Kauppi@fi.flextronics.com>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Tuesday, February 18, 2003 7:34 AM
Subject: Need for help...


>
> Does anyone know what 'lua_newuserdata()' really is and why / where it
> should be used?
>
> I'm doing an (experimental) gluax compatibility cover over old-style C
API.
>
> The following extract is from 'luasocket.c':
>
>     /* declare new Lua tags for used userdata values */
>     p_tags tags = (p_tags) lua_newuserdata(L, sizeof(t_tags));
>     tags->client = lua_newtag(L);
>     tags->server = lua_newtag(L);
>     tags->table = lua_newtag(L);
>     tags->udp = lua_newtag(L);
>
> 'p_tags' is simply (same source file):
>
> typedef struct t_tags {
>     int client, server, table, udp;
> } t_tags;
> typedef t_tags *p_tags;
>
> Question is, what is really the importance / need for 'lua_newuserdata()'?
> It's not documented in 4.0 PDF and in my understanding, is just a fancy
> 'alloc'. I must be missing something...?
>
> Declaration in 'luaapi.c':
>
> LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
>   TString *ts = luaS_newudata(L, size, NULL);
>   tsvalue(L->top) = ts;
>   ttype(L->top) = LUA_TUSERDATA;
>   api_incr_top(L);
>   return ts->u.d.value;
> }
>
> -ak
>
> ###########################################
> This message has been scanned by F-Secure Anti-Virus for Microsoft
Exchange.
>