lua-users home
lua-l archive

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


Peter Hill wrote:
Eero Pajarre:

Btw. I became curious about what Peter had suggested year ago. I think
that what he wanted (protected datatypes in Lua)...


Do you mean the idea of making true Abstract Types by hiding the
internals with some sort of locked tags as a key? Ie:

I was mostly thinking along the lines of the code provided by Björn,
using closures for data hiding.

If so, you've got a good memory! I didn't think at the time that anybody
even noticed the suggestion.


(No, I cheated and checked the archives on www.lua-users.org)

I'm having trouble trying to imagine a way to get the same functionality
(which doesn't mean it can't be done of course!). As an example, let's try
to implement complex numbers as an abstract type. With the tag-key method we
have:


Thinking of, it I see problems with the implementation, although some sort
of encapsulation can be achieved. I will have to consider this more...


What did people generally use (a) upvalues and (b) tag methods for?

What were the forces / desires that have generated the new (a) setglobals
(b) lexical scope and (c) metatables... and how well are they achieving
those goals?

I am still new to more advanced Lua features. I am currently
using setglobals for catching programming errors, (For example
by disabling accidental creation of new global variables), I think
I might use it also for creating a "sandbox" for untrusted code.

I am not yet actively using lexical scoping, but I did not use
upvalues either...

Metatables I use both in my glue code to C/C++ stuff and also
for doing "object oriented Lua" (classes, stating on inheritance)
(I think these were the two typical uses for tags also)


		Eero