diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | .luacheckrc | 5 | ||||
| -rw-r--r-- | LICENSE | 22 | ||||
| -rw-r--r-- | init.lua | 116 | ||||
| -rw-r--r-- | locale/luablock.es.tr | 8 | ||||
| -rw-r--r-- | locale/template.txt | 8 | ||||
| -rw-r--r-- | mod.conf | 3 | ||||
| -rw-r--r-- | textures/luablock_luablock.png | bin | 0 -> 1144 bytes |
8 files changed, 164 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ffc8a2e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +i18n.py +locale/*.old diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..6ec5413 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,5 @@ +max_line_length = 160 +read_globals = { + "core", + "vector", +} @@ -0,0 +1,22 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..bd498f4 --- /dev/null +++ b/init.lua @@ -0,0 +1,116 @@ +local S = core.get_translator("luablock") + +local function on_receive_fields(pos,_,fields,player) + if not fields.save then return end + if not player then return end + local name = player:get_player_name() + if not core.check_player_privs(name,{server=true}) then + core.chat_send_player(name,S("You need the 'server' privilege to use this!")) + return + end + local meta = core.get_meta(pos) + meta:set_string("code",fields.code) + meta:set_string("infotext",S("Lua Block (operating normally)")) +end + +local function run(pos,event) + local env = {} + for k,v in pairs(_G) do env[k] = v end + env.event = event + local meta = core.get_meta(pos) + local code = meta:get_string("code") + local func,loaderr = loadstring(code) + if not func then + meta:set_string("infotext",S("Lua Block (error)").."\n"..loaderr) + return + end + setfenv(func,env) + local ok,err = pcall(func) + --The code may have removed the Lua block as it ran + local nname = core.get_node(pos).name + if nname ~= "luablock:luablock" and nname ~= "luablock:luablock_on" then return end + if ok then + meta:set_string("infotext",S("Lua Block (operating normally)")) + else + meta:set_string("infotext",S("Lua Block (error)").."\n"..err) + end +end + +local rules = { + vector.new(-1,0,0), + vector.new(1,0,0), + vector.new(0,0,-1), + vector.new(0,0,1), +} +local mesecons = { + effector = { + rules = rules, + action_on = function(pos,node) + node.name = "luablock:luablock_on" + core.swap_node(pos,node) + run(pos,{pos=pos,type="on"}) + end, + action_off = function(pos,node) + node.name = "luablock:luablock" + core.swap_node(pos,node) + end, + } +} + +local digilines = { + receptor = {}, + effector = { + action = function(pos,_,channel,msg) + run(pos,{channel=channel,msg=msg,pos=pos}) + end, + }, +} + +core.register_node("luablock:luablock",{ + description = S("Lua Block"), + tiles = { + "luablock_luablock.png", + }, + groups = { + cracky = 2, + not_in_creative_inventory = 1, + }, + after_place_node = function(pos,player) + if not player then return end + local name = player:get_player_name() + if not core.check_player_privs(name,{server=true}) then + core.remove_node(pos) + core.chat_send_player(name,S("You need the 'server' privilege to use this!")) + return true + end + local meta = core.get_meta(pos) + local fs = "formspec_version[10]" + fs = fs.."size[20,15]" + fs = fs.."textarea[0.25,0.25;19.5,13;code;;${code}]" + fs = fs.."button[9,13.5;2,1;save;"..S("Save").."]" + meta:set_string("formspec",fs) + meta:set_string("infotext",S("Lua Block (unprogrammed)")) + end, + on_receive_fields = on_receive_fields, + mesecons = mesecons, + digilines = digilines, +}) + +core.register_node("luablock:luablock_on",{ + drop = "luablock:luablock", + description = S("Lua Block (on - you hacker you!)"), + tiles = { + "luablock_luablock.png^[brighten", + }, + groups = { + cracky = 2, + not_in_creative_inventory = 1, + }, + after_place_node = function(pos) + core.remove_node(pos) + return true + end, + on_receive_fields = on_receive_fields, + mesecons = mesecons, + digilines = digilines, +}) diff --git a/locale/luablock.es.tr b/locale/luablock.es.tr new file mode 100644 index 0000000..ff6186f --- /dev/null +++ b/locale/luablock.es.tr @@ -0,0 +1,8 @@ +# textdomain: luablock +You need the 'server' privilege to use this!=¡Necesitas el privilegio «server» para usar esto! +Lua Block (operating normally)=Bloque de Lua (funcionamiento normal) +Lua Block (error)=Bloque de Lua (error) +Lua Block=Bloque de Lua +Save=Guardar +Lua Block (unprogrammed)=Bloque de Lua (no programado) +Lua Block (on - you hacker you!)=Bloque de Lua (estado activado) diff --git a/locale/template.txt b/locale/template.txt new file mode 100644 index 0000000..30b027e --- /dev/null +++ b/locale/template.txt @@ -0,0 +1,8 @@ +# textdomain: luablock +You need the 'server' privilege to use this!= +Lua Block (operating normally)= +Lua Block (error)= +Lua Block= +Save= +Lua Block (unprogrammed)= +Lua Block (on - you hacker you!)= diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..fa36fae --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = luablock +description = Simple node that runs configurable Lua code on a mesecons or digilines signal +optional_depends = mesecons,digilines diff --git a/textures/luablock_luablock.png b/textures/luablock_luablock.png Binary files differnew file mode 100644 index 0000000..d0b2946 --- /dev/null +++ b/textures/luablock_luablock.png |
