mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-26 02:10:18 +01:00
Publish some LuaC API (#348)
This commit is contained in:
parent
748446b3cc
commit
cc860acf8a
@ -522,6 +522,23 @@ local digiline = {
|
|||||||
end
|
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)
|
local function on_receive_fields(pos, form_name, fields, sender)
|
||||||
if not fields.program then
|
if not fields.program then
|
||||||
return
|
return
|
||||||
@ -531,12 +548,10 @@ local function on_receive_fields(pos, form_name, fields, sender)
|
|||||||
minetest.record_protection_violation(pos, name)
|
minetest.record_protection_violation(pos, name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
reset(pos)
|
local ok, err = set_program(pos, fields.code)
|
||||||
reset_meta(pos, fields.code)
|
if not ok then
|
||||||
local err = run(pos, {type="program"})
|
-- it's not an error from the server perspective
|
||||||
if err then
|
minetest.log("action", "Lua controller programming error: " .. err)
|
||||||
print(err)
|
|
||||||
reset_meta(pos, fields.code, err)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -590,7 +605,11 @@ for d = 0, 1 do
|
|||||||
receptor = {
|
receptor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
rules = output_rules[cid]
|
rules = output_rules[cid]
|
||||||
}
|
},
|
||||||
|
luacontroller = {
|
||||||
|
get_program = get_program,
|
||||||
|
set_program = set_program,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_node(node_name, {
|
minetest.register_node(node_name, {
|
||||||
|
Loading…
Reference in New Issue
Block a user