lua-users home
lua-l archive

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


On 4 May 2015 at 05:02, Philipp Janda <siffiejoe@gmx.net> wrote:
I usually use something like

    local s = [[
    local logger, RLC = ...
    return function (cpu)
      -- some code
    end
    ]]

    local f = assert(load(s, s, "t", {}))(logger, RLC)

for this.

And using this approach, you can even hide the fact that you are creating locals:

local input = [[
function (cpu)
  logger.debug("RLC %s")
  cpu.%s = RLC(cpu, cpu.%s)
  cpu.PC = (cpu.PC + 2) & 0xffff
end
]]

... somewhere in your code, this can be "ugly" with as many "local" variables as you want:
local s = [[local logger, RLC = ...\n]] .. input
local f = assert(load(s, s, "t", {}))(logger, RLC)