lua-users home
lua-l archive

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


On Thu, Jul 8, 2010 at 11:50 AM, Nicolas <nicolas@net-core.org> wrote:
> So I thought I could modify the parser to save the string that defined
> a function inside the function structure itself so I could later use it.

why not do it in Lua?

do
  local storedfuncs={}
  local prevloadstring = loadstring

  function loadstring (code)
    local f = assert (prevloadstring(code))
    storedfuncs[f] = code
    return f
  end

  function getcode (f)
    return storedfuncs[f]
  end
end



now every call to loadstring will store a copy of the source code used
to create a given chunk, use getcode(f) to retrieve it.



-- 
Javier