lua-users home
lua-l archive

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


On Mon, Jun 15, 2009 at 12:09 PM, Sivan wrote:
> I thought there would be an another way to handle this, by adjusting the lua
> local space.

The limit in the number of locals has been mentioned before, e.g. [1].
 Though a workaround is to rewrite your code using local table(s),
perhaps the Lua compiler could be modified to do that transformation
transparently....

  -- before
  local a = 11
  repeat
    local b = 12
    local c = 13
    ...
    print(a, b, c, ...)
    if x then break end
    ....
  until false

  -- after
  local __locals = {}
  __locals[1] = 11
  repeat
    __locals[2] = 12
    __locals[3] = 13
    ...
    print(__locals[1], __locals[2], __locals[3], ...)
    if x then
      ...
      __locals[3] = nil
      __locals[2] = nil
      break
    end
    ...
    __locals[3] = nil
    __locals[2] = nil
  until false
  __locals = nil

Note: the code execution on scope exit proposal might help here.

The limit on number of elements in a concatenation [2] might be solved likewise.

[1] http://lua-users.org/lists/lua-l/2008-05/msg00278.html
[2] http://lua-users.org/wiki/AssociativityOfConcatenation