lua-users home
lua-l archive

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


On Wed, Feb 26, 2014 at 5:04 AM, Journeyer J. Joh
<oosaprogrammer@gmail.com> wrote:
> Many lua OO libraries are all or nothing for virtual function. This means
> they treat methods always virtual or always non-virtual. But YACI is
> different. With YACI, I can set a certain function virtual or non-virtual.
> It gives me power to configure a class' method.


I don't see the relation between virtual/nonvirtual functions and
class/instance methods.

in C++, if you don't declare a method as virtual, then the static type
of the variable is used to choose the exact version of the method
(early binding).  if it's virtual, then the type of the value is used
instead (late binding)

class methods OTOH are methods that don't take a 'this' pointer.  of
course, since there's no value, they can only be static. (at least on
C++.  if classes are values, there are easy ways to do late-binding of
class methods)


as Steve pointed, on dynamic languages variables don't have type.
values do.  therefore, every method is 'virtual'.

I don't see how you could call a 'nonvirtual' method, since there's
there are no static types.  maybe you could specify the class you want
as part of the call.

in Lua, it could be something like:

obj:method(args...)  -- typical 'virtual' method

class.method(obj, args...)   -- specific class version.

Of course, this works without any help from the OO implementation
library, but it's totally in the hands of the object user, not the
object writer.


class methods are a different thing, and i guess it could be simply:

class:method(args, ...)

that is, a method where the object is the class.  the exact syntax to
define the class method depends on the specific OO library.


-- 
Javier