Added optional param stripDebug to string.dump

This commit is contained in:
Enyby
2018-09-16 15:21:16 +03:00
committed by GitHub
parent 63ca0f94af
commit f164c1cd28

View File

@@ -162,20 +162,22 @@ public class StringLib extends TwoArgFunction {
} }
/** /**
* string.dump (function) * string.dump (function[, stripDebug])
* *
* Returns a string containing a binary representation of the given function, * Returns a string containing a binary representation of the given function,
* so that a later loadstring on this string returns a copy of the function. * so that a later loadstring on this string returns a copy of the function.
* function must be a Lua function without upvalues. * function must be a Lua function without upvalues.
* Boolean param stripDebug - true to strip debugging info, false otherwise.
* The default value for stripDebug is true.
* *
* TODO: port dumping code as optional add-on * TODO: port dumping code as optional add-on
*/ */
static final class dump extends OneArgFunction { static final class dump extends VarArgFunction {
public LuaValue call(LuaValue arg) { public LuaValue invoke(Varargs args) {
LuaValue f = arg.checkfunction(); LuaValue f = args.checkfunction(1);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
try { try {
DumpState.dump( ((LuaClosure)f).p, baos, true ); DumpState.dump( ((LuaClosure)f).p, baos, args.optboolean(2, true) );
return LuaString.valueUsing(baos.toByteArray()); return LuaString.valueUsing(baos.toByteArray());
} catch (IOException e) { } catch (IOException e) {
return error( e.getMessage() ); return error( e.getMessage() );