[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Seriali[sz]ation of functions...
- From: Duck <duck@...>
- Date: Sun, 17 Feb 2008 15:40:19 +1100 (EST)
When seriali[sz]ing a function (e.g. as a subroutine when seriali[sz]ing a
table), it seems that you need to use string.dump() at one end and
loadstring() at the other.
But lexical scoping confuses the issue -- the refman says that the
argument to string.dump 'must be a Lua function with no upvalues,' but
doesn't enforce this restriction when it is called. This means that you
can inadvertently dump() a function with upvalues, which will almost
certainly provoke a run-time error when you 'undump' it later in another
Is there any way to determine that a function is suitable for
seriali[sz]ation with string.dump() other than by using debug.getupvalue()
to check if it has upvalues?
(I ask because it seems that the debug library is something that a
security-conscious Lua script might want to disable at run-time in
production use. Of course, a security-conscious script might not want to
allow (de)seriali[sz]ation of functions, but that is another matter :-)