Compare commits

...

3 Commits

Author SHA1 Message Date
imre84 2242c5a631
Merge 8a3f46153c into f75700ed76 2024-04-15 22:43:44 +00:00
Imre Péntek 8a3f46153c doc fix, coding style fix 2024-04-16 00:41:57 +02:00
Imre Péntek ea05043273 doc updated 2024-04-16 00:38:50 +02:00
2 changed files with 8 additions and 6 deletions

View File

@ -227,9 +227,9 @@ Code
----
Contained in code.lua, this module allows arbitrary Lua code to be used with WorldEdit.
### error = worldedit.lua(code,name)
### error = worldedit.lua(code, name)
the given code gets encapsulated into a function with parameters `name`, `player`, pos`
the given code gets encapsulated into a function with parameters `name`, `player`, `pos`
where
* `name` is a playername or `nil`
* `player` is the player object of the above player if applicable, otherwise `nil`
@ -237,7 +237,9 @@ where
the resulting function is then executed as a Lua chunk in the global namespace.
The return is a tuple of success and return of the function converted to a string, which in turn serves as an error messsage in case of a failure
The return is
* a string in case of an error
* a tuple of `nil` and return of the function converted to a string in case of success
### error = worldedit.luatransform(pos1, pos2, code)

View File

@ -6,10 +6,10 @@
-- * name (the name of the player issuing the //lua command)
-- * player (the player object of the above player if applicable)
-- * pos (the position of the aforementioned player (if applicable) rounded to integers
-- @return tuple of success, return of code as string (error message in case of failure)
-- @return string in case of error, tuple of nil, return of code as string in case of success
function worldedit.lua(code, name)
if string.sub(code,1,1)=="=" then
code="return "..string.sub(code,2)
if string.sub(code, 1, 1) == "=" then
code = "return " .. string.sub(code, 2)
end
local factory, err = loadstring("return function(name, player, pos) " .. code .. " end")
if not factory then -- Syntax error