diff options
| -rw-r--r-- | worldedit/code.lua | 46 | ||||
| -rw-r--r-- | worldedit/manipulations.lua | 4 | 
2 files changed, 29 insertions, 21 deletions
| diff --git a/worldedit/code.lua b/worldedit/code.lua index fb04ce9..dc58299 100644 --- a/worldedit/code.lua +++ b/worldedit/code.lua @@ -1,7 +1,9 @@  worldedit = worldedit or {}
 -local minetest = minetest --local copy of global
 +local minetest = minetest -- local copy of global
 ---modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
 +-- Copies and modifies positions `pos1` and `pos2` so that each component of
 +-- `pos1` is less than or equal to the corresponding component of `pos2`.
 +-- Returns the new positions.
  worldedit.sort_pos = function(pos1, pos2)
  	pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
  	pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
 @@ -17,30 +19,33 @@ worldedit.sort_pos = function(pos1, pos2)  	return pos1, pos2
  end
 ---executes `code` as a Lua chunk in the global namespace, returning an error if the code fails or nil otherwise
 +-- Executes `code` as a Lua chunk in the global namespace,
 +-- returning an error if the code fails, or nil otherwise.
  worldedit.lua = function(code)
 -	local operation, message = loadstring(code)
 -	if operation == nil then --code parsing failed
 -		return message
 +	local func, err = loadstring(code)
 +	if not func then  -- Syntax error
 +		return err
  	end
 -	local status, message = pcall(operation)
 -	if status == nil then --operation failed
 -		return message
 +	local good, err = pcall(operation)
 +	if not good then  -- Runtime error
 +		return err
  	end
  	return nil
  end
 ---executes `code` as a Lua chunk in the global namespace with the variable pos available, for each node in a region defined by positions `pos1` and `pos2`, returning an error if the code fails or nil otherwise
 +-- Executes `code` as a Lua chunk in the global namespace with the variable
 +-- pos available, for each node in a region defined by positions `pos1` and
 +-- `pos2`, returning an error if the code fails, or nil otherwise
  worldedit.luatransform = function(pos1, pos2, code)
 -	local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
 +	pos1, pos2 = worldedit.sort_pos(pos1, pos2)
 -	local factory, message = loadstring("return function(pos) " .. code .. " end")
 -	if factory == nil then --code parsing failed
 -		return message
 +	local factory, err = loadstring("return function(pos) " .. code .. " end")
 +	if not factory then  -- Syntax error
 +		return err
  	end
 -	local operation = factory()
 +	local func = factory()
 -	--make area stay loaded
 +	-- Keep area loaded
  	local manip = minetest.get_voxel_manip()
  	manip:read_from_map(pos1, pos2)
 @@ -50,9 +55,9 @@ worldedit.luatransform = function(pos1, pos2, code)  		while pos.y <= pos2.y do
  			pos.z = pos1.z
  			while pos.z <= pos2.z do
 -				local status, message = pcall(operation, pos)
 -				if status == nil then --operation failed
 -					return message
 +				local good, err = pcall(func, pos)
 +				if not good then -- Runtime error
 +					return err
  				end
  				pos.z = pos.z + 1
  			end
 @@ -61,4 +66,5 @@ worldedit.luatransform = function(pos1, pos2, code)  		pos.x = pos.x + 1
  	end
  	return nil
 -end
\ No newline at end of file +end
 +
 diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 2e3e369..71eef5d 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -1,7 +1,9 @@  worldedit = worldedit or {}
  local minetest = minetest --local copy of global
 ---modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
 +-- Copies and modifies positions `pos1` and `pos2` so that each component of
 +-- `pos1` is less than or equal to the corresponding component of `pos2`.
 +-- Returns the new positions.
  worldedit.sort_pos = function(pos1, pos2)
  	pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
  	pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
 | 
