Skip to content

Commit

Permalink
Bugfix for string.dump() and converted instruction data.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcuth committed May 15, 2014
1 parent ca6d7a5 commit adff2ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/scripts/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ assertTrue (type(f) == 'function', 'loadstring() should return a function when p
local result = f()
assertTrue (result == 'hello', 'The function returned from loadstring() should return the value from the script')

local s = string.dump(function () return 'bar' end)
f = loadstring(s)
result = f()

assertTrue (result == 'bar', 'loadstring() should be able to create a function from the output of string.dump()')



Expand Down
2 changes: 1 addition & 1 deletion test/test-package.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion vm/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,16 @@ var shine = shine || {};


dump: function (func) {
return JSON.stringify(func._data);
var data = func._data,
result = shine.gc.createObject(),
i;

for (i in data) {
if (data.hasOwnProperty(i)) result[i] = data[i];
}

result.instructions = Array.apply(shine.gc.createArray(), result.instructions);
return JSON.stringify(result);
},


Expand Down

0 comments on commit adff2ed

Please sign in to comment.