lua-users home
lua-l archive

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


Tim Gogolin wrote:
I also had a need to retrieve the source for a given lua function.
The two approaches I could see were:

1) Write a lua parser


I have hacked lua2html so that it's now a keyword parser.

using a table similar to :

  local keyword_depth = {
    ['function']  = 1,
    ['if']        = 1,
    ['do']        = 1,
    ['end']       = -1,
  }

I can then parse out the function end. This is good enough for my current needs - when i've tidied it up && packaged it properly.
What i'm tempted to do is create a luaX_getinfo() or similar.
Or maybe luaX_getsource(), and return a string. (This could also be lua-callable)

Any ideas ?
Adrian

ps if lua 5.1 includes an end_line value in lua_getinfo(), that would solve it....