Search found 650 matches

by airstruck
Thu Jun 18, 2015 2:44 pm
Forum: Libraries and Tools
Topic: Base - a class-based OOP micro-module
Replies: 3
Views: 2292

Re: Base - a class-based OOP micro-module

The only thing I'd add personally is an :is() method for instances Personally I don't need that kind of typechecking that often, so I just settle for a property like isFoo = true on a Foo class. I'm not sure if I want to add it, but if you want you could monkey-patch Base: function Base:is (super) ...
by airstruck
Wed Jun 17, 2015 9:15 pm
Forum: Libraries and Tools
Topic: Base - a class-based OOP micro-module
Replies: 3
Views: 2292

Base - a class-based OOP micro-module

A micro-module for class-based* OOP: return { extend = function (self, subtype) return setmetatable(subtype or {}, { __index = self, __call = function (self, ...) local instance = setmetatable({}, { __index = self }) return instance, instance:constructor(...) end }) end, constructor = function () en...
by airstruck
Wed Jun 17, 2015 2:11 pm
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

Using the second option, you just need to create C, implement the class-specific methods on it (like printClass) When I read "implement the class-specific methods on it," it sounds an awful lot like you mean implement the methods that weren't implemented on the superclass. I don't see how...
by airstruck
Wed Jun 17, 2015 3:28 am
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

Sure, but what did kikito's post have to do with duck typing? He seems to be advocating for subtype polymorphism, not duck typing. I don't see any feature detection (as in your example) in his post or anything else I'd normally associate with duck typing. What's the connection? Or are we just callin...
by airstruck
Wed Jun 17, 2015 1:17 am
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

Xgoff wrote:tl;dr: duck typing
Could you explain what you mean by that? To me that post seems to be about favoring subtype polymorphism over typechecking; I'm not seeing the connection to duck typing.
by airstruck
Tue Jun 16, 2015 9:41 pm
Forum: Libraries and Tools
Topic: Aspect - an extremely minimal ECS module
Replies: 8
Views: 4778

Re: Aspect - an extremely minimal ECS module

Thanks, I may tweak it a little more though. Might have cache enabled by default and user has to explicity disable it per entities list. Would encourage clearing the cache at appropriate times, so people don't add caching after they write all their systems and break stuff. Maybe also a user-configur...
by airstruck
Tue Jun 16, 2015 9:28 pm
Forum: Libraries and Tools
Topic: memoize.lua
Replies: 35
Views: 18143

Re: memoize.lua

Robin wrote:Also uses nilKey if args == false.

Ahh yeah, good catch. Fixed.
by airstruck
Mon Jun 15, 2015 9:15 pm
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

A __type metamethod sounds like it could be pretty useful indeed. I think it might do more harm than good. It's nice knowing that type will return one of a small set of possible values. If you want to know whether something is a function or table, but instead type is returning something like "...
by airstruck
Mon Jun 15, 2015 8:52 pm
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

You could have a __type metamethod and then override the default type() function to call the metamethod if it has it, or other was call the old type function if it doesn't. Shadowing type sounds like asking for trouble, it's going to take anyone else looking at the code a few minutes to figure out ...
by airstruck
Mon Jun 15, 2015 8:12 pm
Forum: Support and Development
Topic: Custom types in Lua
Replies: 17
Views: 12059

Re: Custom types in Lua

I think someone suggested a __type metamethod once on the lists but it didn't gain any traction. For any "class" where you want to check if some object is an "instance" of it, you could just put a property in the prototype like isWhatever = true . If you're doing this kind of typ...