aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-03-30 21:59:30 +0200
committerorwell96 <mono96.mml@gmail.com>2017-03-30 22:17:54 +0200
commit327b12d488a7f001e21826a5b9e1df03af44c7ae (patch)
tree26f3ef2759c2f7764bbe0f21a7df5f1735f4f9ae /advtrains/advtrains_luaautomation
parent606c129f5796eb56e9abd1049954cf1ca0b8f410 (diff)
downloadadvtrains-327b12d488a7f001e21826a5b9e1df03af44c7ae.tar.gz
advtrains-327b12d488a7f001e21826a5b9e1df03af44c7ae.tar.bz2
advtrains-327b12d488a7f001e21826a5b9e1df03af44c7ae.zip
Assert some variable types obtained from lua automation
Diffstat (limited to 'advtrains/advtrains_luaautomation')
-rw-r--r--advtrains/advtrains_luaautomation/atc_rail.lua4
-rw-r--r--advtrains/advtrains_luaautomation/init.lua7
2 files changed, 11 insertions, 0 deletions
diff --git a/advtrains/advtrains_luaautomation/atc_rail.lua b/advtrains/advtrains_luaautomation/atc_rail.lua
index 141f119..ab84986 100644
--- a/advtrains/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains/advtrains_luaautomation/atc_rail.lua
@@ -48,6 +48,7 @@ function r.fire_event(pos, evtdata)
local customfct={
atc_send = function(cmd)
if not train_id then return false end
+ assertt(cmd, "string")
advtrains.atc.train_reset_command(train_id)
train.atc_command=cmd
train.atc_arrow=atc_arrow
@@ -55,6 +56,7 @@ function r.fire_event(pos, evtdata)
end,
atc_reset = function(cmd)
if not train_id then return false end
+ assertt(cmd, "string")
advtrains.atc.train_reset_command(train_id)
return true
end,
@@ -63,11 +65,13 @@ function r.fire_event(pos, evtdata)
atc_speed = tvel,
atc_set_text_outside = function(text)
if not train_id then return false end
+ if text then assertt(text, "string") end
advtrains.trains[train_id].text_outside=text
return true
end,
atc_set_text_inside = function(text)
if not train_id then return false end
+ if text then assertt(text, "string") end
advtrains.trains[train_id].text_inside=text
return true
end,
diff --git a/advtrains/advtrains_luaautomation/init.lua b/advtrains/advtrains_luaautomation/init.lua
index 87f5921..71808e7 100644
--- a/advtrains/advtrains_luaautomation/init.lua
+++ b/advtrains/advtrains_luaautomation/init.lua
@@ -16,6 +16,13 @@ atlatc = { envs = {}}
minetest.register_privilege("atlatc", { description = "Player can place and modify LUA ATC components. Grant with care! Allows to execute bad LUA code.", give_to_singleplayer = false, default= false })
+--assertt helper. error if a variable is not of a type
+function assertt(var, typ)
+ if type(var)~=typ then
+ error("Assertion failed, variable has to be of type "..typ)
+ end
+end
+
local mp=minetest.get_modpath("advtrains_luaautomation")
if not mp then
error("Mod name error: Mod folder is not named 'advtrains_luaautomation'!")