[英]Design questions for an OOP library in Lua
I implemented a small OOP library in Lua, and two things are not quite right yet.我在 Lua 中实现了一个小型的 OOP 库,有两件事还不太对。 I need your advice!
我需要你的建议!
I need to make a choice.我需要做出选择。 The three arguments I need to resolve a call to super() are:
我需要解决对 super() 的调用的三个参数是:
I hesitate between these three forms:我在这三种形式之间犹豫不决:
--# Current way:
self:super(CallerClass):method()
--# Variant, which I now find cleaner:
CallerClass:super(self):method()
--# Python style, which is nice too:
super(CallerClass, self):method()
Which one looks nicer and or easier to remember to you?哪一个看起来更好或更容易记住?
In the current version, the only concept is a table named Object
, which you can subclass.在当前版本中,唯一的概念是名为
Object
的表,您可以将其子类化。 I have another version where I introduced a Class symbol.我有另一个版本,我在其中引入了 Class 符号。
Its use is to tell instances from classes.它的用途是从类中区分实例。 Ie :
IE :
assert(Object:isKindOf(Class))
local object = Object:new()
assert(not object:isKindOf(Class))
I find it very handy to document and enforce that a method must be called from a class, by starting the method with:我发现记录和强制必须从类调用方法非常方便,方法是通过以下方式启动:
assert(self:isKindOf(Class))
Is it usefull in Lua?它在 Lua 中有用吗? What do you think?
你怎么认为? Thanks!
谢谢!
--# Python style, which is nice too:
super(CallerClass, self):method()
我会说有一个类对象 - 更多的信息/元数据更好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.