Enforced mod global naming convention and better error reporting

This commit is contained in:
Perttu Ahola 2011-12-03 02:45:55 +02:00
parent 581f950e10
commit d96cd236f3
7 changed files with 258 additions and 140 deletions

@ -1,12 +1,12 @@
minetest.register_craft({ minetest.register_craft({
output = 'craft "bucket" 1', output = 'craft "bucket_empty" 1',
recipe = { recipe = {
{'craft "steel_ingot"', '', 'craft "steel_ingot"'}, {'craft "steel_ingot"', '', 'craft "steel_ingot"'},
{'', 'craft "steel_ingot"', ''}, {'', 'craft "steel_ingot"', ''},
} }
}) })
minetest.register_craftitem("bucket", { minetest.register_craftitem("bucket_empty", {
image = "bucket.png", image = "bucket.png",
stack_max = 1, stack_max = 1,
liquids_pointable = true, liquids_pointable = true,
@ -43,7 +43,7 @@ minetest.register_craftitem("bucket_water", {
else else
minetest.env:add_node(pointed_thing.above, {name="water_source"}) minetest.env:add_node(pointed_thing.above, {name="water_source"})
end end
player:add_to_inventory_later('craft "bucket" 1') player:add_to_inventory_later('craft "bucket_empty" 1')
return true return true
end end
return false return false
@ -65,7 +65,7 @@ minetest.register_craftitem("bucket_lava", {
else else
minetest.env:add_node(pointed_thing.above, {name="lava_source"}) minetest.env:add_node(pointed_thing.above, {name="lava_source"})
end end
player:add_to_inventory_later('craft "bucket" 1') player:add_to_inventory_later('craft "bucket_empty" 1')
return true return true
end end
return false return false

@ -2,10 +2,30 @@
-- dump2(obj, name="_", dumped={}) -- dump2(obj, name="_", dumped={})
-- dump(obj, dumped={}) -- dump(obj, dumped={})
-- --
-- Textures: -- Naming convention for registered textual names
-- Mods should prefix their textures with modname_, eg. given the mod -- ----------------------------------------------
-- name "foomod", a texture could be called "foomod_superfurnace.png" -- "modname_<whatever>"
-- Due to historical reasons, the default mod does not follow this rule. --
-- This is to prevent conflicting names from corrupting maps and is
-- enforced by the mod loader.
--
-- Example: mod "experimental", ideal item/node/entity name "tnt":
-- -> the name should be "experimental_tnt".
--
-- Enforcement can be overridden by prefixing the name with ":". This can
-- be used for overriding the registrations of some other mod.
--
-- Default mod uses ":" for maintaining backwards compatibility.
--
-- Textures
-- --------
-- Mods should generally prefix their textures with modname_, eg. given
-- the mod name "foomod", a texture could be called "foomod_superfurnace.png"
--
-- This is not crucial and a conflicting name will not corrupt maps.
--
-- Representations of simple things
-- --------------------------------
-- --
-- MapNode representation: -- MapNode representation:
-- {name="name", param1=num, param2=num} -- {name="name", param1=num, param2=num}
@ -220,7 +240,7 @@
-- } -- }
-- --
-- Craftitem definition options: -- Craftitem definition options:
-- minetest.register_craftitem("name", { -- minetest.register_craftitem(":name", {
-- image = "image.png", -- image = "image.png",
-- stack_max = <maximum number of items in stack>, -- stack_max = <maximum number of items in stack>,
-- cookresult_item = itemstring (result of cooking), -- cookresult_item = itemstring (result of cooking),
@ -256,7 +276,7 @@ LIGHT_MAX = 14
-- Tool definition -- Tool definition
-- --
minetest.register_tool("WPick", { minetest.register_tool(":WPick", {
image = "tool_woodpick.png", image = "tool_woodpick.png",
basetime = 2.0, basetime = 2.0,
dt_weight = 0, dt_weight = 0,
@ -269,7 +289,7 @@ minetest.register_tool("WPick", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("STPick", { minetest.register_tool(":STPick", {
image = "tool_stonepick.png", image = "tool_stonepick.png",
basetime = 1.5, basetime = 1.5,
dt_weight = 0, dt_weight = 0,
@ -282,7 +302,7 @@ minetest.register_tool("STPick", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("SteelPick", { minetest.register_tool(":SteelPick", {
image = "tool_steelpick.png", image = "tool_steelpick.png",
basetime = 1.0, basetime = 1.0,
dt_weight = 0, dt_weight = 0,
@ -295,7 +315,7 @@ minetest.register_tool("SteelPick", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("MesePick", { minetest.register_tool(":MesePick", {
image = "tool_mesepick.png", image = "tool_mesepick.png",
basetime = 0, basetime = 0,
dt_weight = 0, dt_weight = 0,
@ -308,7 +328,7 @@ minetest.register_tool("MesePick", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("WShovel", { minetest.register_tool(":WShovel", {
image = "tool_woodshovel.png", image = "tool_woodshovel.png",
basetime = 2.0, basetime = 2.0,
dt_weight = 0.5, dt_weight = 0.5,
@ -321,7 +341,7 @@ minetest.register_tool("WShovel", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("STShovel", { minetest.register_tool(":STShovel", {
image = "tool_stoneshovel.png", image = "tool_stoneshovel.png",
basetime = 1.5, basetime = 1.5,
dt_weight = 0.5, dt_weight = 0.5,
@ -334,7 +354,7 @@ minetest.register_tool("STShovel", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("SteelShovel", { minetest.register_tool(":SteelShovel", {
image = "tool_steelshovel.png", image = "tool_steelshovel.png",
basetime = 1.0, basetime = 1.0,
dt_weight = 0.5, dt_weight = 0.5,
@ -347,7 +367,7 @@ minetest.register_tool("SteelShovel", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("WAxe", { minetest.register_tool(":WAxe", {
image = "tool_woodaxe.png", image = "tool_woodaxe.png",
basetime = 2.0, basetime = 2.0,
dt_weight = 0.5, dt_weight = 0.5,
@ -360,7 +380,7 @@ minetest.register_tool("WAxe", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("STAxe", { minetest.register_tool(":STAxe", {
image = "tool_stoneaxe.png", image = "tool_stoneaxe.png",
basetime = 1.5, basetime = 1.5,
dt_weight = 0.5, dt_weight = 0.5,
@ -373,7 +393,7 @@ minetest.register_tool("STAxe", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("SteelAxe", { minetest.register_tool(":SteelAxe", {
image = "tool_steelaxe.png", image = "tool_steelaxe.png",
basetime = 1.0, basetime = 1.0,
dt_weight = 0.5, dt_weight = 0.5,
@ -386,7 +406,7 @@ minetest.register_tool("SteelAxe", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("WSword", { minetest.register_tool(":WSword", {
image = "tool_woodsword.png", image = "tool_woodsword.png",
basetime = 3.0, basetime = 3.0,
dt_weight = 3, dt_weight = 3,
@ -399,7 +419,7 @@ minetest.register_tool("WSword", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("STSword", { minetest.register_tool(":STSword", {
image = "tool_stonesword.png", image = "tool_stonesword.png",
basetime = 2.5, basetime = 2.5,
dt_weight = 3, dt_weight = 3,
@ -412,7 +432,7 @@ minetest.register_tool("STSword", {
dd_crumbliness = 0, dd_crumbliness = 0,
dd_cuttability = 0, dd_cuttability = 0,
}) })
minetest.register_tool("SteelSword", { minetest.register_tool(":SteelSword", {
image = "tool_steelsword.png", image = "tool_steelsword.png",
basetime = 2.0, basetime = 2.0,
dt_weight = 3, dt_weight = 3,
@ -426,7 +446,7 @@ minetest.register_tool("SteelSword", {
dd_cuttability = 0, dd_cuttability = 0,
}) })
-- The hand -- The hand
minetest.register_tool("", { minetest.register_tool(":", {
image = "", image = "",
basetime = 0.5, basetime = 0.5,
dt_weight = 1, dt_weight = 1,
@ -794,7 +814,7 @@ end
-- Legacy nodes -- Legacy nodes
minetest.register_node("stone", { minetest.register_node(":stone", {
tile_images = {"stone.png"}, tile_images = {"stone.png"},
inventory_image = inventorycube("stone.png"), inventory_image = inventorycube("stone.png"),
paramtype = "mineral", paramtype = "mineral",
@ -804,7 +824,7 @@ minetest.register_node("stone", {
dug_item = 'node "cobble" 1', dug_item = 'node "cobble" 1',
}) })
minetest.register_node("dirt_with_grass", { minetest.register_node(":dirt_with_grass", {
tile_images = {"grass.png", "mud.png", "mud.png^grass_side.png"}, tile_images = {"grass.png", "mud.png", "mud.png^grass_side.png"},
inventory_image = inventorycube("mud.png^grass_side.png"), inventory_image = inventorycube("mud.png^grass_side.png"),
is_ground_content = true, is_ground_content = true,
@ -812,7 +832,7 @@ minetest.register_node("dirt_with_grass", {
dug_item = 'node "dirt" 1', dug_item = 'node "dirt" 1',
}) })
minetest.register_node("dirt_with_grass_footsteps", { minetest.register_node(":dirt_with_grass_footsteps", {
tile_images = {"grass_footsteps.png", "mud.png", "mud.png^grass_side.png"}, tile_images = {"grass_footsteps.png", "mud.png", "mud.png^grass_side.png"},
inventory_image = "grass_footsteps.png", inventory_image = "grass_footsteps.png",
is_ground_content = true, is_ground_content = true,
@ -820,14 +840,14 @@ minetest.register_node("dirt_with_grass_footsteps", {
dug_item = 'node "dirt" 1', dug_item = 'node "dirt" 1',
}) })
minetest.register_node("dirt", { minetest.register_node(":dirt", {
tile_images = {"mud.png"}, tile_images = {"mud.png"},
inventory_image = inventorycube("mud.png"), inventory_image = inventorycube("mud.png"),
is_ground_content = true, is_ground_content = true,
material = digprop_dirtlike(1.0), material = digprop_dirtlike(1.0),
}) })
minetest.register_node("sand", { minetest.register_node(":sand", {
tile_images = {"sand.png"}, tile_images = {"sand.png"},
inventory_image = inventorycube("sand.png"), inventory_image = inventorycube("sand.png"),
is_ground_content = true, is_ground_content = true,
@ -835,14 +855,14 @@ minetest.register_node("sand", {
cookresult_item = 'node "glass" 1', cookresult_item = 'node "glass" 1',
}) })
minetest.register_node("gravel", { minetest.register_node(":gravel", {
tile_images = {"gravel.png"}, tile_images = {"gravel.png"},
inventory_image = inventorycube("gravel.png"), inventory_image = inventorycube("gravel.png"),
is_ground_content = true, is_ground_content = true,
material = digprop_gravellike(1.0), material = digprop_gravellike(1.0),
}) })
minetest.register_node("sandstone", { minetest.register_node(":sandstone", {
tile_images = {"sandstone.png"}, tile_images = {"sandstone.png"},
inventory_image = inventorycube("sandstone.png"), inventory_image = inventorycube("sandstone.png"),
is_ground_content = true, is_ground_content = true,
@ -850,7 +870,7 @@ minetest.register_node("sandstone", {
dug_item = 'node "sand" 1', -- FIXME is this intentional? dug_item = 'node "sand" 1', -- FIXME is this intentional?
}) })
minetest.register_node("clay", { minetest.register_node(":clay", {
tile_images = {"clay.png"}, tile_images = {"clay.png"},
inventory_image = inventorycube("clay.png"), inventory_image = inventorycube("clay.png"),
is_ground_content = true, is_ground_content = true,
@ -858,7 +878,7 @@ minetest.register_node("clay", {
dug_item = 'craft "lump_of_clay" 4', dug_item = 'craft "lump_of_clay" 4',
}) })
minetest.register_node("brick", { minetest.register_node(":brick", {
tile_images = {"brick.png"}, tile_images = {"brick.png"},
inventory_image = inventorycube("brick.png"), inventory_image = inventorycube("brick.png"),
is_ground_content = true, is_ground_content = true,
@ -866,7 +886,7 @@ minetest.register_node("brick", {
dug_item = 'craft "clay_brick" 4', dug_item = 'craft "clay_brick" 4',
}) })
minetest.register_node("tree", { minetest.register_node(":tree", {
tile_images = {"tree_top.png", "tree_top.png", "tree.png"}, tile_images = {"tree_top.png", "tree_top.png", "tree.png"},
inventory_image = inventorycube("tree_top.png", "tree.png", "tree.png"), inventory_image = inventorycube("tree_top.png", "tree.png", "tree.png"),
is_ground_content = true, is_ground_content = true,
@ -875,7 +895,7 @@ minetest.register_node("tree", {
furnace_burntime = 30, furnace_burntime = 30,
}) })
minetest.register_node("jungletree", { minetest.register_node(":jungletree", {
tile_images = {"jungletree_top.png", "jungletree_top.png", "jungletree.png"}, tile_images = {"jungletree_top.png", "jungletree_top.png", "jungletree.png"},
inventory_image = inventorycube("jungletree_top.png", "jungletree.png", "jungletree.png"), inventory_image = inventorycube("jungletree_top.png", "jungletree.png", "jungletree.png"),
is_ground_content = true, is_ground_content = true,
@ -884,7 +904,7 @@ minetest.register_node("jungletree", {
furnace_burntime = 30, furnace_burntime = 30,
}) })
minetest.register_node("junglegrass", { minetest.register_node(":junglegrass", {
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = 1.3, visual_scale = 1.3,
tile_images = {"junglegrass.png"}, tile_images = {"junglegrass.png"},
@ -896,7 +916,7 @@ minetest.register_node("junglegrass", {
furnace_burntime = 2, furnace_burntime = 2,
}) })
minetest.register_node("leaves", { minetest.register_node(":leaves", {
drawtype = "allfaces_optional", drawtype = "allfaces_optional",
visual_scale = 1.3, visual_scale = 1.3,
tile_images = {"leaves.png"}, tile_images = {"leaves.png"},
@ -909,7 +929,7 @@ minetest.register_node("leaves", {
furnace_burntime = 1, furnace_burntime = 1,
}) })
minetest.register_node("cactus", { minetest.register_node(":cactus", {
tile_images = {"cactus_top.png", "cactus_top.png", "cactus_side.png"}, tile_images = {"cactus_top.png", "cactus_top.png", "cactus_side.png"},
inventory_image = inventorycube("cactus_top.png", "cactus_side.png", "cactus_side.png"), inventory_image = inventorycube("cactus_top.png", "cactus_side.png", "cactus_side.png"),
is_ground_content = true, is_ground_content = true,
@ -917,7 +937,7 @@ minetest.register_node("cactus", {
furnace_burntime = 15, furnace_burntime = 15,
}) })
minetest.register_node("papyrus", { minetest.register_node(":papyrus", {
drawtype = "plantlike", drawtype = "plantlike",
tile_images = {"papyrus.png"}, tile_images = {"papyrus.png"},
inventory_image = "papyrus.png", inventory_image = "papyrus.png",
@ -929,7 +949,7 @@ minetest.register_node("papyrus", {
furnace_burntime = 1, furnace_burntime = 1,
}) })
minetest.register_node("bookshelf", { minetest.register_node(":bookshelf", {
tile_images = {"wood.png", "wood.png", "bookshelf.png"}, tile_images = {"wood.png", "wood.png", "bookshelf.png"},
-- FIXME: inventorycube only cares for the first texture -- FIXME: inventorycube only cares for the first texture
--inventory_image = inventorycube("wood.png", "bookshelf.png", "bookshelf.png") --inventory_image = inventorycube("wood.png", "bookshelf.png", "bookshelf.png")
@ -939,7 +959,7 @@ minetest.register_node("bookshelf", {
furnace_burntime = 30, furnace_burntime = 30,
}) })
minetest.register_node("glass", { minetest.register_node(":glass", {
drawtype = "glasslike", drawtype = "glasslike",
tile_images = {"glass.png"}, tile_images = {"glass.png"},
inventory_image = inventorycube("glass.png"), inventory_image = inventorycube("glass.png"),
@ -950,7 +970,7 @@ minetest.register_node("glass", {
material = digprop_glasslike(1.0), material = digprop_glasslike(1.0),
}) })
minetest.register_node("wooden_fence", { minetest.register_node(":wooden_fence", {
drawtype = "fencelike", drawtype = "fencelike",
tile_images = {"wood.png"}, tile_images = {"wood.png"},
inventory_image = "fence.png", inventory_image = "fence.png",
@ -965,7 +985,7 @@ minetest.register_node("wooden_fence", {
material = digprop_woodlike(0.75), material = digprop_woodlike(0.75),
}) })
minetest.register_node("rail", { minetest.register_node(":rail", {
drawtype = "raillike", drawtype = "raillike",
tile_images = {"rail.png", "rail_curved.png", "rail_t_junction.png", "rail_crossing.png"}, tile_images = {"rail.png", "rail_curved.png", "rail_t_junction.png", "rail_crossing.png"},
inventory_image = "rail.png", inventory_image = "rail.png",
@ -980,7 +1000,7 @@ minetest.register_node("rail", {
material = digprop_dirtlike(0.75), material = digprop_dirtlike(0.75),
}) })
minetest.register_node("ladder", { minetest.register_node(":ladder", {
drawtype = "signlike", drawtype = "signlike",
tile_images = {"ladder.png"}, tile_images = {"ladder.png"},
inventory_image = "ladder.png", inventory_image = "ladder.png",
@ -1000,14 +1020,14 @@ minetest.register_node("ladder", {
material = digprop_woodlike(0.5), material = digprop_woodlike(0.5),
}) })
minetest.register_node("coalstone", { minetest.register_node(":coalstone", {
tile_images = {"stone.png^mineral_coal.png"}, tile_images = {"stone.png^mineral_coal.png"},
inventory_image = "stone.png^mineral_coal.png", inventory_image = "stone.png^mineral_coal.png",
is_ground_content = true, is_ground_content = true,
material = digprop_stonelike(1.5), material = digprop_stonelike(1.5),
}) })
minetest.register_node("wood", { minetest.register_node(":wood", {
tile_images = {"wood.png"}, tile_images = {"wood.png"},
inventory_image = inventorycube("wood.png"), inventory_image = inventorycube("wood.png"),
is_ground_content = true, is_ground_content = true,
@ -1015,7 +1035,7 @@ minetest.register_node("wood", {
material = digprop_woodlike(0.75), material = digprop_woodlike(0.75),
}) })
minetest.register_node("mese", { minetest.register_node(":mese", {
tile_images = {"mese.png"}, tile_images = {"mese.png"},
inventory_image = inventorycube("mese.png"), inventory_image = inventorycube("mese.png"),
is_ground_content = true, is_ground_content = true,
@ -1023,13 +1043,13 @@ minetest.register_node("mese", {
material = digprop_stonelike(0.5), material = digprop_stonelike(0.5),
}) })
minetest.register_node("cloud", { minetest.register_node(":cloud", {
tile_images = {"cloud.png"}, tile_images = {"cloud.png"},
inventory_image = inventorycube("cloud.png"), inventory_image = inventorycube("cloud.png"),
is_ground_content = true, is_ground_content = true,
}) })
minetest.register_node("water_flowing", { minetest.register_node(":water_flowing", {
drawtype = "flowingliquid", drawtype = "flowingliquid",
tile_images = {"water.png"}, tile_images = {"water.png"},
alpha = WATER_ALPHA, alpha = WATER_ALPHA,
@ -1051,7 +1071,7 @@ minetest.register_node("water_flowing", {
}, },
}) })
minetest.register_node("water_source", { minetest.register_node(":water_source", {
drawtype = "liquid", drawtype = "liquid",
tile_images = {"water.png"}, tile_images = {"water.png"},
alpha = WATER_ALPHA, alpha = WATER_ALPHA,
@ -1073,7 +1093,7 @@ minetest.register_node("water_source", {
}, },
}) })
minetest.register_node("lava_flowing", { minetest.register_node(":lava_flowing", {
drawtype = "flowingliquid", drawtype = "flowingliquid",
tile_images = {"lava.png"}, tile_images = {"lava.png"},
inventory_image = inventorycube("lava.png"), inventory_image = inventorycube("lava.png"),
@ -1096,7 +1116,7 @@ minetest.register_node("lava_flowing", {
}, },
}) })
minetest.register_node("lava_source", { minetest.register_node(":lava_source", {
drawtype = "liquid", drawtype = "liquid",
tile_images = {"lava.png"}, tile_images = {"lava.png"},
inventory_image = inventorycube("lava.png"), inventory_image = inventorycube("lava.png"),
@ -1120,7 +1140,7 @@ minetest.register_node("lava_source", {
furnace_burntime = 60, furnace_burntime = 60,
}) })
minetest.register_node("torch", { minetest.register_node(":torch", {
drawtype = "torchlike", drawtype = "torchlike",
tile_images = {"torch_on_floor.png", "torch_on_ceiling.png", "torch.png"}, tile_images = {"torch_on_floor.png", "torch_on_ceiling.png", "torch.png"},
inventory_image = "torch_on_floor.png", inventory_image = "torch_on_floor.png",
@ -1140,7 +1160,7 @@ minetest.register_node("torch", {
furnace_burntime = 4, furnace_burntime = 4,
}) })
minetest.register_node("sign_wall", { minetest.register_node(":sign_wall", {
drawtype = "signlike", drawtype = "signlike",
tile_images = {"sign_wall.png"}, tile_images = {"sign_wall.png"},
inventory_image = "sign_wall.png", inventory_image = "sign_wall.png",
@ -1160,7 +1180,7 @@ minetest.register_node("sign_wall", {
furnace_burntime = 10, furnace_burntime = 10,
}) })
minetest.register_node("chest", { minetest.register_node(":chest", {
tile_images = {"chest_top.png", "chest_top.png", "chest_side.png", tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
"chest_side.png", "chest_side.png", "chest_front.png"}, "chest_side.png", "chest_side.png", "chest_front.png"},
inventory_image = "chest_top.png", inventory_image = "chest_top.png",
@ -1171,7 +1191,7 @@ minetest.register_node("chest", {
furnace_burntime = 30, furnace_burntime = 30,
}) })
minetest.register_node("locked_chest", { minetest.register_node(":locked_chest", {
tile_images = {"chest_top.png", "chest_top.png", "chest_side.png", tile_images = {"chest_top.png", "chest_top.png", "chest_side.png",
"chest_side.png", "chest_side.png", "chest_lock.png"}, "chest_side.png", "chest_side.png", "chest_lock.png"},
inventory_image = "chest_lock.png", inventory_image = "chest_lock.png",
@ -1181,7 +1201,7 @@ minetest.register_node("locked_chest", {
furnace_burntime = 30, furnace_burntime = 30,
}) })
minetest.register_node("furnace", { minetest.register_node(":furnace", {
tile_images = {"furnace_side.png", "furnace_side.png", "furnace_side.png", tile_images = {"furnace_side.png", "furnace_side.png", "furnace_side.png",
"furnace_side.png", "furnace_side.png", "furnace_front.png"}, "furnace_side.png", "furnace_side.png", "furnace_front.png"},
inventory_image = "furnace_front.png", inventory_image = "furnace_front.png",
@ -1190,7 +1210,7 @@ minetest.register_node("furnace", {
material = digprop_stonelike(3.0), material = digprop_stonelike(3.0),
}) })
minetest.register_node("cobble", { minetest.register_node(":cobble", {
tile_images = {"cobble.png"}, tile_images = {"cobble.png"},
inventory_image = inventorycube("cobble.png"), inventory_image = inventorycube("cobble.png"),
is_ground_content = true, is_ground_content = true,
@ -1198,21 +1218,21 @@ minetest.register_node("cobble", {
material = digprop_stonelike(0.9), material = digprop_stonelike(0.9),
}) })
minetest.register_node("mossycobble", { minetest.register_node(":mossycobble", {
tile_images = {"mossycobble.png"}, tile_images = {"mossycobble.png"},
inventory_image = inventorycube("mossycobble.png"), inventory_image = inventorycube("mossycobble.png"),
is_ground_content = true, is_ground_content = true,
material = digprop_stonelike(0.8), material = digprop_stonelike(0.8),
}) })
minetest.register_node("steelblock", { minetest.register_node(":steelblock", {
tile_images = {"steel_block.png"}, tile_images = {"steel_block.png"},
inventory_image = inventorycube("steel_block.png"), inventory_image = inventorycube("steel_block.png"),
is_ground_content = true, is_ground_content = true,
material = digprop_stonelike(5.0), material = digprop_stonelike(5.0),
}) })
minetest.register_node("nyancat", { minetest.register_node(":nyancat", {
tile_images = {"nc_side.png", "nc_side.png", "nc_side.png", tile_images = {"nc_side.png", "nc_side.png", "nc_side.png",
"nc_side.png", "nc_back.png", "nc_front.png"}, "nc_side.png", "nc_back.png", "nc_front.png"},
inventory_image = "nc_front.png", inventory_image = "nc_front.png",
@ -1221,14 +1241,14 @@ minetest.register_node("nyancat", {
furnace_burntime = 1, furnace_burntime = 1,
}) })
minetest.register_node("nyancat_rainbow", { minetest.register_node(":nyancat_rainbow", {
tile_images = {"nc_rb.png"}, tile_images = {"nc_rb.png"},
inventory_image = "nc_rb.png", inventory_image = "nc_rb.png",
material = digprop_stonelike(3.0), material = digprop_stonelike(3.0),
furnace_burntime = 1, furnace_burntime = 1,
}) })
minetest.register_node("sapling", { minetest.register_node(":sapling", {
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = 1.0, visual_scale = 1.0,
tile_images = {"sapling.png"}, tile_images = {"sapling.png"},
@ -1240,7 +1260,7 @@ minetest.register_node("sapling", {
furnace_burntime = 10, furnace_burntime = 10,
}) })
minetest.register_node("apple", { minetest.register_node(":apple", {
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = 1.0, visual_scale = 1.0,
tile_images = {"apple.png"}, tile_images = {"apple.png"},
@ -1258,51 +1278,51 @@ minetest.register_node("apple", {
-- Crafting items -- Crafting items
-- --
minetest.register_craftitem("Stick", { minetest.register_craftitem(":Stick", {
image = "stick.png", image = "stick.png",
--furnace_burntime = ..., --furnace_burntime = ...,
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("paper", { minetest.register_craftitem(":paper", {
image = "paper.png", image = "paper.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("book", { minetest.register_craftitem(":book", {
image = "book.png", image = "book.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("lump_of_coal", { minetest.register_craftitem(":lump_of_coal", {
image = "lump_of_coal.png", image = "lump_of_coal.png",
furnace_burntime = 40; furnace_burntime = 40;
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("lump_of_iron", { minetest.register_craftitem(":lump_of_iron", {
image = "lump_of_iron.png", image = "lump_of_iron.png",
cookresult_item = 'craft "steel_ingot" 1', cookresult_item = 'craft "steel_ingot" 1',
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("lump_of_clay", { minetest.register_craftitem(":lump_of_clay", {
image = "lump_of_clay.png", image = "lump_of_clay.png",
cookresult_item = 'craft "clay_brick" 1', cookresult_item = 'craft "clay_brick" 1',
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("steel_ingot", { minetest.register_craftitem(":steel_ingot", {
image = "steel_ingot.png", image = "steel_ingot.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("clay_brick", { minetest.register_craftitem(":clay_brick", {
image = "clay_brick.png", image = "clay_brick.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("rat", { minetest.register_craftitem(":rat", {
image = "rat.png", image = "rat.png",
cookresult_item = 'craft "cooked_rat" 1', cookresult_item = 'craft "cooked_rat" 1',
on_drop = function(item, dropper, pos) on_drop = function(item, dropper, pos)
@ -1311,19 +1331,19 @@ minetest.register_craftitem("rat", {
end, end,
}) })
minetest.register_craftitem("cooked_rat", { minetest.register_craftitem(":cooked_rat", {
image = "cooked_rat.png", image = "cooked_rat.png",
cookresult_item = 'craft "scorched_stuff" 1', cookresult_item = 'craft "scorched_stuff" 1',
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(6), on_use = minetest.craftitem_eat(6),
}) })
minetest.register_craftitem("scorched_stuff", { minetest.register_craftitem(":scorched_stuff", {
image = "scorched_stuff.png", image = "scorched_stuff.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem("firefly", { minetest.register_craftitem(":firefly", {
image = "firefly.png", image = "firefly.png",
on_drop = function(item, dropper, pos) on_drop = function(item, dropper, pos)
minetest.env:add_firefly(pos) minetest.env:add_firefly(pos)
@ -1331,13 +1351,13 @@ minetest.register_craftitem("firefly", {
end, end,
}) })
minetest.register_craftitem("apple", { minetest.register_craftitem(":apple", {
image = "apple.png", image = "apple.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(4), on_use = minetest.craftitem_eat(4),
}) })
minetest.register_craftitem("apple_iron", { minetest.register_craftitem(":apple_iron", {
image = "apple_iron.png", image = "apple_iron.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
on_use = minetest.craftitem_eat(8), on_use = minetest.craftitem_eat(8),
@ -1389,7 +1409,7 @@ function nodeupdate_single(p)
n_bottom = minetest.env:get_node(p_bottom) n_bottom = minetest.env:get_node(p_bottom)
if n_bottom.name == "air" then if n_bottom.name == "air" then
minetest.env:remove_node(p) minetest.env:remove_node(p)
minetest.env:add_luaentity(p, "falling_"..n.name) minetest.env:add_luaentity(p, "default_falling_"..n.name)
nodeupdate(p) nodeupdate(p)
end end
end end
@ -1411,7 +1431,7 @@ end
-- --
function register_falling_node(nodename, texture) function register_falling_node(nodename, texture)
minetest.register_entity("falling_"..nodename, { minetest.register_entity("default_falling_"..nodename, {
-- Static definition -- Static definition
physical = true, physical = true,
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
@ -1452,26 +1472,18 @@ end
minetest.register_globalstep(on_step) minetest.register_globalstep(on_step)
function on_placenode(p, node) function on_placenode(p, node)
print("on_placenode") --print("on_placenode")
nodeupdate(p) nodeupdate(p)
end end
minetest.register_on_placenode(on_placenode) minetest.register_on_placenode(on_placenode)
function on_dignode(p, node) function on_dignode(p, node)
print("on_dignode") --print("on_dignode")
nodeupdate(p) nodeupdate(p)
end end
minetest.register_on_dignode(on_dignode) minetest.register_on_dignode(on_dignode)
function on_punchnode(p, node) function on_punchnode(p, node)
print("on_punchnode")
if node.name == "TNT" then
minetest.env:remove_node(p)
minetest.env:add_luaentity(p, "TNT")
--minetest.env:add_luaentity(p, "testentity")
--minetest.env:add_firefly(p)
nodeupdate(p)
end
end end
minetest.register_on_punchnode(on_punchnode) minetest.register_on_punchnode(on_punchnode)

@ -4,7 +4,7 @@
-- An example furnace-thing implemented in Lua -- An example furnace-thing implemented in Lua
minetest.register_node("luafurnace", { minetest.register_node("experimental_luafurnace", {
tile_images = {"lava.png", "furnace_side.png", "furnace_side.png", tile_images = {"lava.png", "furnace_side.png", "furnace_side.png",
"furnace_side.png", "furnace_side.png", "furnace_front.png"}, "furnace_side.png", "furnace_side.png", "furnace_front.png"},
--inventory_image = "furnace_front.png", --inventory_image = "furnace_front.png",
@ -15,7 +15,7 @@ minetest.register_node("luafurnace", {
}) })
minetest.register_on_placenode(function(pos, newnode, placer) minetest.register_on_placenode(function(pos, newnode, placer)
if newnode.name == "luafurnace" then if newnode.name == "experimental_luafurnace" then
print("get_meta"); print("get_meta");
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
print("inventory_set_list"); print("inventory_set_list");
@ -42,7 +42,7 @@ minetest.register_on_placenode(function(pos, newnode, placer)
end) end)
minetest.register_abm({ minetest.register_abm({
nodenames = {"luafurnace"}, nodenames = {"experimental_luafurnace"},
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
@ -97,7 +97,7 @@ minetest.register_abm({
}) })
minetest.register_craft({ minetest.register_craft({
output = 'node "luafurnace" 1', output = 'node "experimental_luafurnace" 1',
recipe = { recipe = {
{'node "cobble"', 'node "cobble"', 'node "cobble"'}, {'node "cobble"', 'node "cobble"', 'node "cobble"'},
{'node "cobble"', 'node "cobble"', 'node "cobble"'}, {'node "cobble"', 'node "cobble"', 'node "cobble"'},
@ -132,7 +132,7 @@ minetest.register_craft({
} }
}) })
minetest.register_node("somenode", { minetest.register_node("experimental_somenode", {
tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"}, tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"},
inventory_image = "treeprop.png", inventory_image = "treeprop.png",
material = { material = {
@ -151,7 +151,7 @@ minetest.register_node("somenode", {
-- --
minetest.register_craft({ minetest.register_craft({
output = 'node "TNT" 4', output = 'node "experimental_tnt" 4',
recipe = { recipe = {
{'node "wood" 1'}, {'node "wood" 1'},
{'craft "lump_of_coal" 1'}, {'craft "lump_of_coal" 1'},
@ -159,7 +159,7 @@ minetest.register_craft({
} }
}) })
minetest.register_node("TNT", { minetest.register_node("experimental_tnt", {
tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"}, tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"},
inventory_image = "tnt_side.png", inventory_image = "tnt_side.png",
dug_item = '', -- Get nothing dug_item = '', -- Get nothing
@ -168,6 +168,14 @@ minetest.register_node("TNT", {
}, },
}) })
minetest.register_on_punchnode(function(p, node)
if node.name == "experimental_tnt" then
minetest.env:remove_node(p)
minetest.env:add_luaentity(p, "experimental_tnt")
nodeupdate(p)
end
end)
local TNT = { local TNT = {
-- Static definition -- Static definition
physical = true, -- Collides with things physical = true, -- Collides with things
@ -225,16 +233,15 @@ function TNT:on_rightclick(clicker)
--self.object:moveto(pos, false) --self.object:moveto(pos, false)
end end
print("TNT dump: "..dump(TNT)) --print("TNT dump: "..dump(TNT))
--print("Registering TNT");
print("Registering TNT"); minetest.register_entity("experimental_tnt", TNT)
minetest.register_entity("TNT", TNT)
-- --
-- A test entity for testing animated and yaw-modulated sprites -- A test entity for testing animated and yaw-modulated sprites
-- --
minetest.register_entity("testentity", { minetest.register_entity("experimental_testentity", {
-- Static definition -- Static definition
physical = true, -- Collides with things physical = true, -- Collides with things
-- weight = 5, -- weight = 5,

@ -31,6 +31,27 @@ extern "C" {
#include <lauxlib.h> #include <lauxlib.h>
} }
LuaError::LuaError(lua_State *L, const std::string &s)
{
m_s = "LuaError: ";
m_s += s + "\n";
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if(lua_istable(L, -1)){
lua_getfield(L, -1, "traceback");
if(lua_isfunction(L, -1)){
lua_call(L, 0, 1);
if(lua_isstring(L, -1)){
m_s += lua_tostring(L, -1);
}
lua_pop(L, 1);
}
else{
lua_pop(L, 1);
}
}
lua_pop(L, 1);
}
void script_error(lua_State *L, const char *fmt, ...) void script_error(lua_State *L, const char *fmt, ...)
{ {
va_list argp; va_list argp;
@ -39,13 +60,34 @@ void script_error(lua_State *L, const char *fmt, ...)
vsnprintf(buf, 10000, fmt, argp); vsnprintf(buf, 10000, fmt, argp);
va_end(argp); va_end(argp);
//errorstream<<"SCRIPT ERROR: "<<buf; //errorstream<<"SCRIPT ERROR: "<<buf;
throw LuaError(buf); throw LuaError(L, buf);
}
int luaErrorHandler(lua_State *L) {
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
return 1;
}
lua_getfield(L, -1, "traceback");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1);
lua_pushinteger(L, 2);
lua_call(L, 2, 1);
return 1;
} }
bool script_load(lua_State *L, const char *path) bool script_load(lua_State *L, const char *path)
{ {
infostream<<"Loading and running script from "<<path<<std::endl; infostream<<"Loading and running script from "<<path<<std::endl;
int ret = luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0);
lua_pushcfunction(L, luaErrorHandler);
int errorhandler = lua_gettop(L);
int ret = luaL_loadfile(L, path) || lua_pcall(L, 0, 0, errorhandler);
if(ret){ if(ret){
errorstream<<"Failed to load and run script from "<<path<<":"<<std::endl; errorstream<<"Failed to load and run script from "<<path<<":"<<std::endl;
errorstream<<"[LUA] "<<std::endl; errorstream<<"[LUA] "<<std::endl;

@ -23,14 +23,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <exception> #include <exception>
#include <string> #include <string>
typedef struct lua_State lua_State;
class LuaError : public std::exception class LuaError : public std::exception
{ {
public: public:
LuaError(const std::string &s) LuaError(lua_State *L, const std::string &s);
{
m_s = "LuaError: ";
m_s += s;
}
virtual ~LuaError() throw() virtual ~LuaError() throw()
{} {}
virtual const char * what() const throw() virtual const char * what() const throw()
@ -40,8 +39,6 @@ public:
std::string m_s; std::string m_s;
}; };
typedef struct lua_State lua_State;
lua_State* script_init(); lua_State* script_init();
void script_deinit(lua_State *L); void script_deinit(lua_State *L);
void script_error(lua_State *L, const char *fmt, ...); void script_error(lua_State *L, const char *fmt, ...);

@ -107,6 +107,59 @@ public:
} }
}; };
class ModNameStorer
{
private:
lua_State *L;
public:
ModNameStorer(lua_State *L_, const std::string modname):
L(L_)
{
// Store current modname in registry
lua_pushstring(L, modname.c_str());
lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname");
}
~ModNameStorer()
{
// Clear current modname in registry
lua_pushnil(L);
lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname");
}
};
std::string get_current_modname(lua_State *L)
{
lua_getfield(L, LUA_REGISTRYINDEX, "minetest_current_modname");
std::string modname = "";
if(lua_type(L, -1) == LUA_TSTRING)
modname = lua_tostring(L, -1);
lua_pop(L, 1);
return modname;
}
void check_modname_prefix(lua_State *L, std::string &name)
{
if(name.size() == 0)
throw LuaError(L, std::string("Name is empty"));
if(name[0] == ':'){
name = name.substr(1);
return;
}
std::string modname = get_current_modname(L);
assert(modname != "");
// For __builtin, anything goes
if(modname == "__builtin")
return;
if(name.substr(0, modname.size()+1) != modname + "_")
throw LuaError(L, std::string("Name \"")+name
+"\" does not follow naming conventions: "
+"\"modname_\" or \":\" prefix required)");
}
static v3f readFloatPos(lua_State *L, int index) static v3f readFloatPos(lua_State *L, int index)
{ {
v3f pos; v3f pos;
@ -470,7 +523,7 @@ static void inventory_get_list_to_lua(Inventory *inv, const char *name,
lua_pushstring(L, item->getItemString().c_str()); lua_pushstring(L, item->getItemString().c_str());
} }
if(lua_pcall(L, 2, 0, 0)) if(lua_pcall(L, 2, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
} }
} }
@ -611,8 +664,9 @@ static int l_register_nodedef_defaults(lua_State *L)
// register_entity(name, prototype) // register_entity(name, prototype)
static int l_register_entity(lua_State *L) static int l_register_entity(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1); std::string name = luaL_checkstring(L, 1);
infostream<<"register_entity: "<<name<<std::endl; check_modname_prefix(L, name);
//infostream<<"register_entity: "<<name<<std::endl;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
// Get minetest.registered_entities // Get minetest.registered_entities
@ -622,7 +676,7 @@ static int l_register_entity(lua_State *L)
int registered_entities = lua_gettop(L); int registered_entities = lua_gettop(L);
lua_pushvalue(L, 2); // Object = param 2 -> stack top lua_pushvalue(L, 2); // Object = param 2 -> stack top
// registered_entities[name] = object // registered_entities[name] = object
lua_setfield(L, registered_entities, name); lua_setfield(L, registered_entities, name.c_str());
// Get registered object to top of stack // Get registered object to top of stack
lua_pushvalue(L, 2); lua_pushvalue(L, 2);
@ -703,14 +757,14 @@ public:
lua_pushnumber(L, active_object_count); lua_pushnumber(L, active_object_count);
lua_pushnumber(L, active_object_count_wider); lua_pushnumber(L, active_object_count_wider);
if(lua_pcall(L, 4, 0, 0)) if(lua_pcall(L, 4, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
} }
}; };
// register_abm({...}) // register_abm({...})
static int l_register_abm(lua_State *L) static int l_register_abm(lua_State *L)
{ {
infostream<<"register_abm"<<std::endl; //infostream<<"register_abm"<<std::endl;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
// Get minetest.registered_abms // Get minetest.registered_abms
@ -744,8 +798,9 @@ static int l_register_abm(lua_State *L)
// register_tool(name, {lots of stuff}) // register_tool(name, {lots of stuff})
static int l_register_tool(lua_State *L) static int l_register_tool(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1); std::string name = luaL_checkstring(L, 1);
infostream<<"register_tool: "<<name<<std::endl; check_modname_prefix(L, name);
//infostream<<"register_tool: "<<name<<std::endl;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
int table = 2; int table = 2;
@ -765,8 +820,9 @@ static int l_register_tool(lua_State *L)
// register_craftitem(name, {lots of stuff}) // register_craftitem(name, {lots of stuff})
static int l_register_craftitem(lua_State *L) static int l_register_craftitem(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1); std::string name = luaL_checkstring(L, 1);
infostream<<"register_craftitem: "<<name<<std::endl; check_modname_prefix(L, name);
//infostream<<"register_craftitem: "<<name<<std::endl;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
int table = 2; int table = 2;
@ -806,7 +862,7 @@ static int l_register_craftitem(lua_State *L)
craftitemdef->registerCraftItem(name, def); craftitemdef->registerCraftItem(name, def);
lua_pushvalue(L, table); lua_pushvalue(L, table);
scriptapi_add_craftitem(L, name); scriptapi_add_craftitem(L, name.c_str());
return 0; /* number of results */ return 0; /* number of results */
} }
@ -814,8 +870,9 @@ static int l_register_craftitem(lua_State *L)
// register_node(name, {lots of stuff}) // register_node(name, {lots of stuff})
static int l_register_node(lua_State *L) static int l_register_node(lua_State *L)
{ {
const char *name = luaL_checkstring(L, 1); std::string name = luaL_checkstring(L, 1);
infostream<<"register_node: "<<name<<std::endl; check_modname_prefix(L, name);
//infostream<<"register_node: "<<name<<std::endl;
luaL_checktype(L, 2, LUA_TTABLE); luaL_checktype(L, 2, LUA_TTABLE);
int nodedef_table = 2; int nodedef_table = 2;
@ -849,7 +906,7 @@ static int l_register_node(lua_State *L)
lua_getglobal(L, "minetest"); lua_getglobal(L, "minetest");
lua_getfield(L, -1, "registered_nodes"); lua_getfield(L, -1, "registered_nodes");
luaL_checktype(L, -1, LUA_TTABLE); luaL_checktype(L, -1, LUA_TTABLE);
lua_pushstring(L, name); lua_pushstring(L, name.c_str());
lua_pushvalue(L, nodedef_table); lua_pushvalue(L, nodedef_table);
lua_settable(L, -3); lua_settable(L, -3);
@ -1054,7 +1111,7 @@ static int l_register_node(lua_State *L)
// register_craft({output=item, recipe={{item00,item10},{item01,item11}}) // register_craft({output=item, recipe={{item00,item10},{item01,item11}})
static int l_register_craft(lua_State *L) static int l_register_craft(lua_State *L)
{ {
infostream<<"register_craft"<<std::endl; //infostream<<"register_craft"<<std::endl;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
int table0 = 1; int table0 = 1;
@ -1104,7 +1161,7 @@ static int l_register_craft(lua_State *L)
std::string error; std::string error;
error += "Invalid crafting recipe (output=\"" error += "Invalid crafting recipe (output=\""
+ output + "\")"; + output + "\")";
throw LuaError(error); throw LuaError(L, error);
} }
} }
// removes value, keeps key for next iteration // removes value, keeps key for next iteration
@ -2475,13 +2532,16 @@ void scriptapi_export(lua_State *L, Server *server)
bool scriptapi_loadmod(lua_State *L, const std::string &scriptpath, bool scriptapi_loadmod(lua_State *L, const std::string &scriptpath,
const std::string &modname) const std::string &modname)
{ {
ModNameStorer modnamestorer(L, modname);
bool success = false; bool success = false;
try{ try{
success = script_load(L, scriptpath.c_str()); success = script_load(L, scriptpath.c_str());
} }
catch(LuaError &e){ catch(LuaError &e){
errorstream<<"Error loading mod: "<<e.what()<<std::endl; errorstream<<"Error loading mod \""<<modname
<<"\": "<<e.what()<<std::endl;
} }
return success; return success;
@ -2567,7 +2627,7 @@ static void dump2(lua_State *L, const char *name)
lua_pushvalue(L, -2); // Get previous stack top as first parameter lua_pushvalue(L, -2); // Get previous stack top as first parameter
lua_pushstring(L, name); lua_pushstring(L, name);
if(lua_pcall(L, 2, 0, 0)) if(lua_pcall(L, 2, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
} }
#endif #endif
@ -2645,7 +2705,7 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name,
lua_pushstring(L, name.c_str()); lua_pushstring(L, name.c_str());
lua_pushstring(L, message.c_str()); lua_pushstring(L, message.c_str());
if(lua_pcall(L, 2, 1, 0)) if(lua_pcall(L, 2, 1, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
bool ate = lua_toboolean(L, -1); bool ate = lua_toboolean(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
if(ate) if(ate)
@ -2678,7 +2738,7 @@ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player)
// Call function // Call function
objectref_get_or_create(L, player); objectref_get_or_create(L, player);
if(lua_pcall(L, 1, 0, 0)) if(lua_pcall(L, 1, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }
@ -2703,7 +2763,7 @@ bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player)
// Call function // Call function
objectref_get_or_create(L, player); objectref_get_or_create(L, player);
if(lua_pcall(L, 1, 1, 0)) if(lua_pcall(L, 1, 1, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
bool positioning_handled = lua_toboolean(L, -1); bool positioning_handled = lua_toboolean(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
if(positioning_handled) if(positioning_handled)
@ -2825,7 +2885,7 @@ bool scriptapi_craftitem_on_drop(lua_State *L, const char *name,
objectref_get_or_create(L, dropper); objectref_get_or_create(L, dropper);
pushFloatPos(L, pos); pushFloatPos(L, pos);
if(lua_pcall(L, 3, 1, 0)) if(lua_pcall(L, 3, 1, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
result = lua_toboolean(L, -1); result = lua_toboolean(L, -1);
} }
return result; return result;
@ -2849,7 +2909,7 @@ bool scriptapi_craftitem_on_place_on_ground(lua_State *L, const char *name,
objectref_get_or_create(L, placer); objectref_get_or_create(L, placer);
pushFloatPos(L, pos); pushFloatPos(L, pos);
if(lua_pcall(L, 3, 1, 0)) if(lua_pcall(L, 3, 1, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
result = lua_toboolean(L, -1); result = lua_toboolean(L, -1);
} }
return result; return result;
@ -2873,7 +2933,7 @@ bool scriptapi_craftitem_on_use(lua_State *L, const char *name,
objectref_get_or_create(L, user); objectref_get_or_create(L, user);
pushPointedThing(L, pointed); pushPointedThing(L, pointed);
if(lua_pcall(L, 3, 1, 0)) if(lua_pcall(L, 3, 1, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
result = lua_toboolean(L, -1); result = lua_toboolean(L, -1);
} }
return result; return result;
@ -2903,7 +2963,7 @@ void scriptapi_environment_step(lua_State *L, float dtime)
// Call function // Call function
lua_pushnumber(L, dtime); lua_pushnumber(L, dtime);
if(lua_pcall(L, 1, 0, 0)) if(lua_pcall(L, 1, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }
@ -2938,7 +2998,7 @@ void scriptapi_environment_on_placenode(lua_State *L, v3s16 p, MapNode newnode,
pushnode(L, newnode, ndef); pushnode(L, newnode, ndef);
objectref_get_or_create(L, placer); objectref_get_or_create(L, placer);
if(lua_pcall(L, 3, 0, 0)) if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }
@ -2973,7 +3033,7 @@ void scriptapi_environment_on_dignode(lua_State *L, v3s16 p, MapNode oldnode,
pushnode(L, oldnode, ndef); pushnode(L, oldnode, ndef);
objectref_get_or_create(L, digger); objectref_get_or_create(L, digger);
if(lua_pcall(L, 3, 0, 0)) if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }
@ -3008,7 +3068,7 @@ void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
pushnode(L, node, ndef); pushnode(L, node, ndef);
objectref_get_or_create(L, puncher); objectref_get_or_create(L, puncher);
if(lua_pcall(L, 3, 0, 0)) if(lua_pcall(L, 3, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }
@ -3034,7 +3094,7 @@ void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp)
pushpos(L, minp); pushpos(L, minp);
pushpos(L, maxp); pushpos(L, maxp);
if(lua_pcall(L, 2, 0, 0)) if(lua_pcall(L, 2, 0, 0))
script_error(L, "error: %s\n", lua_tostring(L, -1)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }
} }

@ -978,7 +978,7 @@ Server::Server(
// Load and run builtin.lua // Load and run builtin.lua
infostream<<"Server: Loading builtin Lua stuff from \""<<builtinpath infostream<<"Server: Loading builtin Lua stuff from \""<<builtinpath
<<"\""<<std::endl; <<"\""<<std::endl;
bool success = script_load(m_lua, builtinpath.c_str()); bool success = scriptapi_loadmod(m_lua, builtinpath, "__builtin");
if(!success){ if(!success){
errorstream<<"Server: Failed to load and run " errorstream<<"Server: Failed to load and run "
<<builtinpath<<std::endl; <<builtinpath<<std::endl;