You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 27, 2021. It is now read-only.
This page covers mixins.
You can easily create a mixin using lobject.mixin
locallobject=require"lobject"localMTalk=lobject.mixin"MTalk" {
talk=function (s) print (s) end
}
There's not much more, the last argument to mixin is in fact a table of functions, nothing more.
Now you can include this either with the class definition or the .include function.
Using lobject.class
localHuman=Class ("Human", MTalk) (function (argl)
-- I haven't been able to implement multiple mixins in the arguments-- Help is appreciated!localobject= {}
object.name=argl.nameor"Unknown"returnobjectend)
Using lobject.include
localHuman=Class ("Human", Being) (function (argl)
-- I haven't been able to implement multiple mixins in the arguments-- Help is appreciated!localobject= {}
object=lobjects.include (object, MTalk)
object.name=argl.nameor"Unknown"returnobjectend)
Pretty simple, huh?
You can also have a special "metamethod" on Mixin tables, they will be executed as soon as the Mixin is processed in the construction process. This key is __mixin_init and it must be set to a function.
locallobject=require"lobject"localMTalk=lobject.mixin"MTalk" {
__mixin_init=function () print"I have been initialized!" end,
talk=function (s) print (s) end
}