[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Modifying the parser to store a function definition
- From: Nicolas <nicolas@...>
- Date: 08 Jul 2010 18:50:28 +0200
Hi,
In my game I make heavy use of having functions inside data structures
which I need to serialize.
Currently I am simply string.dump'ing the functions and it works fine.
However this is not portable between architectures, luajit2 does not
yet support it, and so on.
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.
I do not care for closures and upvalues in such cases so I only need the
code (and string.dump does not handle them anyway).
I quickly found I do not sufficiently know the parser to do that yet, so
has anybody done such a thing?
The tricky part is that it needs to be remembered as just a function, so
that I.E:
function foo(a) print("foo", a) end
is remembered as just:
function(a) print("foo", a) end
So just using ls->lineumber is invalid, it needs the exact position of the
parenthesis.
I tried ls->current for the position but they seem very much off :/
I am open to ideas :)
Thanks