[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How am I supposed to use yaci library?(Yet Another Class Implementation)
- From: Andrew Starks <andrew.starks@...>
- Date: Mon, 24 Feb 2014 22:55:12 -0600
On Monday, February 24, 2014, Journeyer J. Joh <oosaprogrammer@gmail.com> wrote:
Hi Andrew Starks
Thank you for the information.
Does penligh's class library support virtual function?
It looks good but I cannot find virtual function there.
Journeyer
There are no other kind, if I understand correctly.
Given that variables are not typed, there is no way to access another value as one thing or another.
So, if you redefine a method for a derived class, objects made from the new class will always have the derived class's methods.
You stated it nicely, earlier. There are a few concepts that do not map well to lua.
Here, mapping virtual functions vs. an early bound method, would require explicitly calling some kind of "as" accessor method, which doesn't exist as a Penlight feature.
I've patched penlight a bit (I've been meaning to clean it up and post a pull request), so it's hard to remember what it does and doesn't do.
The basics are that you can make a class and any number of derived classes from it. New classes are able to identify themselves as being derived from their base classes. You can emulate an effective, but not strict, private member property/method system by using class.properties. There isn't any concept of "friend" or other sort of nuanced access.
Like lua, it's pragmatic and lightweight, without being overly strict or complete. That said, I sometimes eschew it for the more generic approach of either emulating objects with closures or making my own objects using meta tables.
It's pretty safe to say that a heavy duty object system is possible, but probably not worth it, in most cases.
-Andrew