lua-users home
lua-l archive

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


I'd imagine that a trait system in lua would have a set of trait tests that run before the program, and attach methods. Each trait would be a unique table of requirements and possibly default implementations. Each object would have some way of saying it implements said trait, either explicitly or duck-typed. Instead of verifying input and output parameters, the best you could probably do is run tests. It doesn't seem massively useful, but it could be a nice sort of subset of a class framework. If there's interest, I might try to write one.

On Mon, Nov 26, 2018 at 9:55 PM Coda Highland <chighland@gmail.com> wrote:
On Mon, Nov 26, 2018 at 8:51 PM Soni L. <fakedme@gmail.com> wrote:
>
> Suggestion: Don't assume (or use) inheritance. Or at least don't mix inheritance with components.
>
> Rust has traits, which are somewhat similar to components, but it doesn't have inheritance. That's because mixing traits/components and inheritance is, at best, messy.

So on the one hand, you're completely right. Traits are a much better
model for this than inheritance, and mixing traits and inheritance can
indeed get quite messy.

But on the other hand, that still leaves the matter of "what's the
best way to implement traits in Lua?" as a question to be discussed.

/s/ Adam