lua-users home
lua-l archive

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

I've argued for enhancements to type, but after some educating, I can see why this made no sense. Also, I shouldn't design the solution I want for the problem that I wish solved. It's not enhancements to type that I'm looking for. 

What really happens, and where I get stuck , is in cases where I want to provide flexibility in the interface to a function. There is always a solution, of course. But sometimes the implementation of it isn't worth it and instead the interface is made more rigidly.


I have an object that holds a sequence. I would like to provide a way to accept that object or a sequence of them. Knowing that I have one object or many can be non-trivial, especially if I'm likely to get them from somewhere other than a typical lua oo implementation

Another example is a string. Everything can have tostring called on it. If I want my function to accept a table or a string, how do I know that I don't have an object that is trying to quack like a string? We can all design ways to do this in Lua, but the point is that this is hard to do without sacrificing polymorphism. Sometimes you want something to say, "I am this, but I'm dressed up as that"

So that's it. Providing flexible interfaces might be a bad idea or of limited utility in Lua. I like them and sometimes I find myself abandoning their implementation because of the above scenarios. 

In Lua. 5.3 or in the future, it'd be cool if making flexible interfaces to functions could be made simpler, without sacrificing polymorphism.