[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: Minimal 4.1 OO
- From: kaishaku13@...
- Date: Thu, 11 Apr 2002 10:42:43 -0500
First, thanks for replying Roberto...
>> I just got 4.0 figured out and now would like to know how to port.
> Remember that 4.1w4 is a quite unstable version (regarding specs).
> Everything there may change.
Yes, I am gambling that the difference between 4.1w4 and the next Lua will
be less than the difference between 4.0 and 4.1w4. I thought about it for
weeks but have decided to use whatever's next, and deal with any changes.
>> tags are gone [...]
> They were replaced by metatables. I guess the manual talks about that
> already. (Does it?)
No, that's primarily why I am asking, the Metatable section in the 4.1w4
refman is blank. If they are documented somewhere, that'd be great.
>> and userdatabox seems to be the giant key.
> For creating new objects, newuserdatabox is exactly the same as the
> old pushuserdata. (For a "pushusertag", you first create it and then
> change its metatable.) The only difference between newuserdatabox
> and pushuserdata is that, when Lua already has a userdata with the
> same address/tag, pushuserdata coalesces the new userdata with the old
> one, while newuserdatabox always creates a new one. When creating new
> objects, that situation never happens, so there is no difference between
> the two functions.
I think I've figured it out, but not via any documents, let me know if this
is correct... It looks like every requires a lot more work in lines of code,
but is more flexible and actually more simple I guess...
The init section of my pseudocode would be like this in 4.1w4 :
pushstring "ClassName"
newtable
pushstring "gettable"
pushcfunction gettableFunction
settable -3
pushstring "settable"
pushcfunction settableFunction
settable -3
settable LUA_REGISTRYINDEX // store in registry ?
register "newClass" // the "new" function"
The new function "newClass" no longer does simply pushuserdata but does :
newuserdatabox ClassInstance // which is an object
pushstring "ClassName" // no more tags
gettable LUA_REGISTRYINDEX
setmetatable -2
Finally, my gettable/settable methods can stay exactly as they are.
To me, this is more simple only to people already familiar with Lua. New
users will find this less simple I think... Maybe documentation will help.
Does all that seem about right?
-Toyotomi