Care to explain it? Maybe PM if people are offended by OT posting.
Elsewhere our SABDFL threatened to ban the first one to
stay on topic...
Basically, to keep access private, you need keys that can't be guessed.[1] This rules out strings (and numbers and booleans), but anything that you can generate and store locally is fine. Tables are the least verbose. Most of my class files begin with something like
Code: Select all
local _x = {}
local _y = {}
local _func = {}
and then when I access them throughout the code I have
Code: Select all
DO_SOMETHING_AT_POSITION(self[_x], self[_y])
self[_func](self)
which gets to be a lot of brackets.
My thinking is, so long as I maintain some easily identifiable convention (in this case the leading underscore), I could instead write it as
Code: Select all
DO_SOMETHING_AT_POSITION(self._x, self._y)
self:_func()
and, using the Metalua code walker, search the file for the underscored fields, generate the private keys out of sight (probably favoring something more lightweight like "function() end" over "{}"), and properly inject them into the code.
I'll probably post a fairly basic demo of some stuff today or tomorrow, if you want to look through and see what I'm doing now.
[1] Also, a simple table won't work because somebody could just pass over it with pairs() and collect the keys. I get around this now via a userdata generated by newproxy().
This thread covers the details pretty well, and at the end Roberto seemed inclined to add some protections into how __pairs and next() will interact in Lua 5.2.