[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: type checking tags
- From: "kenlohk" <kenlo@...>
- Date: Thu, 24 Jan 2002 06:10:24 -0000
I found there is no type checking on tags even in core Lua.
Consider these codes,
-- this will hang
p = 123
s = read(p,'*a')
-- this will give error
q = 'I love you'
t = read(q,'*a')
What is the philosophy behind the use of tag? Confusion on
them can give serious errors i.e. core dump. For example I
implemented a userdata with
w = myuserdata_init('something')
x = myuserdata_query(w)
Where in myuserdata_query I need to access a data structure.
If I pass myuserdata_query an abritrary pointer i.e. a pointer
that has not been initialized with myuserdata_init, then I
can core dump. I have tested that. Someone in this list
has advised these codes,
lua_pushusertag(L, 1, newtag())
lua_setglobal(L, mytag)
So mytag becomes global and next time I can check if the
pointer passed is a valid myuserdata. But wait a minute.
Someone can erase mytag or set it to something else. So
what really is the philosophy behind tag?