diff --git a/worldedit/code.lua b/worldedit/code.lua index f985d28..0765e84 100644 --- a/worldedit/code.lua +++ b/worldedit/code.lua @@ -51,7 +51,7 @@ function worldedit.luatransform(pos1, pos2, code) while pos.z <= pos2.z do local good, err = pcall(func, pos) if not good then -- Runtime error - return err + return tostring(err) end pos.z = pos.z + 1 end diff --git a/worldedit/test.lua b/worldedit/test.lua index a8e3ae0..dab9e02 100644 --- a/worldedit/test.lua +++ b/worldedit/test.lua @@ -542,6 +542,43 @@ do end end + +register_test("Code") +register_test("worldedit.lua", function() + -- syntax error + local err, ret = worldedit.lua("?") + assert(ret == nil) + assert(err:find("unexpected symbol")) + + -- runtime error + local err, ret = worldedit.lua("error(1234)") + assert(ret == nil) + assert(err:find("1234")) + + -- normal operation + local err, ret = worldedit.lua("return name..tostring(player == nil)..tostring(pos == nil)", "nobody") + assert(err == nil) + assert(ret == "\"nobodytruetrue\"") +end) + +register_test("worldedit.luatransform", function() + local pos1, pos2 = area.get(2) + + -- syntax error + local err = worldedit.luatransform(pos1, pos2, "?") + assert(err:find("unexpected symbol")) + + -- runtime error + local err = worldedit.luatransform(pos1, pos2, "error(2345)") + assert(err:find("2345")) + + -- normal operation + local err = worldedit.luatransform(pos1, pos2, + "minetest.swap_node(pos, {name=" .. ("%q"):format(testnode1) .. "})") + assert(err == nil) + check.filled(pos1, pos1, testnode1) +end) + --------------------- -- Main function ---------------------