diff options
author | Vitaliy <silverunicorn2011@yandex.ru> | 2017-10-18 22:54:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-18 22:54:28 +0300 |
commit | cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56 (patch) | |
tree | 1f700a7dd0c3dbf31e050990241c66637f6dcb7d | |
parent | 748446b3cc4d663764e632c9de62eff2e530b44c (diff) | |
download | mesecons-cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56.tar mesecons-cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56.tar.gz mesecons-cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56.tar.bz2 mesecons-cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56.tar.xz mesecons-cc860acf8a4d0c7c0a8c814bdf0aceada72e2b56.zip |
Publish some LuaC API (#348)
-rw-r--r-- | mesecons_luacontroller/init.lua | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index ea285d4..93703d8 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -522,6 +522,23 @@ local digiline = { end } } + +local function get_program(pos) + local meta = minetest.get_meta(pos) + return meta:get_string("code") +end + +local function set_program(pos, code) + reset(pos) + reset_meta(pos, code) + local err = run(pos, {type="program"}) + if err then + reset_meta(pos, code, err) + return false, err + end + return true +end + local function on_receive_fields(pos, form_name, fields, sender) if not fields.program then return @@ -531,12 +548,10 @@ local function on_receive_fields(pos, form_name, fields, sender) minetest.record_protection_violation(pos, name) return end - reset(pos) - reset_meta(pos, fields.code) - local err = run(pos, {type="program"}) - if err then - print(err) - reset_meta(pos, fields.code, err) + local ok, err = set_program(pos, fields.code) + if not ok then + -- it's not an error from the server perspective + minetest.log("action", "Lua controller programming error: " .. err) end end @@ -590,7 +605,11 @@ for d = 0, 1 do receptor = { state = mesecon.state.on, rules = output_rules[cid] - } + }, + luacontroller = { + get_program = get_program, + set_program = set_program, + }, } minetest.register_node(node_name, { |