lua-users home
lua-l archive

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


>  x:do_something(5)  -- Clearly should be a function.
>  x:name()  -- Called as a function, even though it's just data?
>  x.name    -- Returned as a string -- is this better?

For the second case I'd use if: x:get_name() or x:getName() which
wasnt that unusual in other OO-oriented languages where it wasn't
possible to set a property to readonly puplic.

I encountered the same question, not for C types, but an opaque handle
in Lua which was filled over its metatable only. I came to conclusion
that I'll use property syntax for simple values where getting them has
no effect and when they are calcuated upon get, its very minor cpu
impact only. For anything that actually creates an object or what
could be one of those profiling bottle necks I implemented in a way so
the user sees it as a call.