-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class.properties to handle _self #48
Comments
Interesting! Let me give it a think. BTW, the stripped-down version of class() in Microlight (see ml.class near the end of ml.lua) has provision for the constructor to return a new self. setmetatable(klass,{
__call = function(klass,...)
local obj = setmetatable({},klass)
if rawget(klass,'_init') then
klass.super = base_ctor
local res = klass._init(obj,...) -- call our constructor
if res then -- which can return a new self..
obj = setmetatable(res,klass)
end
elseif base_ctor then -- call base ctor automatically
base_ctor(obj,...)
end
return obj
end
}) (It occurs to me that if that new self was nil, and |
I saw that too, but I got stuck thinking that there were perhaps 3 entry On Fri, Feb 15, 2013 at 12:15 AM, Steve J Donovan
|
Hey Steve, Did you get my attachments/emails for the changes I made to PL, so that it second, I applied the necessary patch to PL to make classes fail upon receiving Near the end of call_ctor:
like. and inside mt.__call
all nice like. This seems to work well for me. -Andrew
|
Nope, didn't arrive here - you used the gmail address? |
Nope. I don't think I have that... unless it's on the lua list. On Wed, Feb 20, 2013 at 4:39 AM, Steve J Donovan
|
OK, new feature is that a class may define |
Hey @andrewstarks do you still use |
Sometimes, I want a class that is handling array data and I want to check input that is entered directly onto the class.
class.properties works well for this, IF you are working on a member of the object, not directly on indexes of the object, itself.
The following is a patch of the class.properties._class_init function (BTW: _class_init needs documentation! :))
The additional overhead is not high. Two extra
if``s during operation, provided
_self` is not used. The code is not much longer, if you remove my over-commenting.In operation, the get_self and set_self work as expected. No attempt to block access to
_self
is made, except that it is hidden as an upvalue to the metatable, so that it does not appear in ipairs or pairs operations. Therefore, class construction is made simple by referencingself._self
as needed, or simply not providing aset_self
method.Things to consider:
The text was updated successfully, but these errors were encountered: