2012-12-01 22:57:51 +06:00
|
|
|
function table:contains(v)
|
|
|
|
for _, i in ipairs(self) do
|
2012-10-30 16:04:35 +06:00
|
|
|
if i == v then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-10-31 18:36:51 +06:00
|
|
|
function table:get_index(value)
|
|
|
|
for i, v in ipairs(self) do
|
|
|
|
if v == value then
|
|
|
|
return i
|
2012-10-30 16:04:35 +06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function hacky_swap_node(pos,name)
|
|
|
|
local node = minetest.env:get_node(pos)
|
|
|
|
local meta = minetest.env:get_meta(pos)
|
|
|
|
local meta0 = meta:to_table()
|
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
local meta0 = meta:to_table()
|
|
|
|
minetest.env:set_node(pos,node)
|
|
|
|
meta = minetest.env:get_meta(pos)
|
|
|
|
meta:from_table(meta0)
|
|
|
|
end
|
2012-10-31 13:29:10 +06:00
|
|
|
|
|
|
|
function string:capitalize()
|
|
|
|
return self:sub(1,1):upper()..self:sub(2):lower()
|
|
|
|
end
|
2012-11-26 17:17:12 +06:00
|
|
|
|
|
|
|
function string:remove_modname_prefix()
|
|
|
|
local i = self:find(":")
|
|
|
|
if i then
|
|
|
|
return self:sub(i+1)
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
2012-12-02 00:20:05 +06:00
|
|
|
|
2013-04-22 16:49:01 +06:00
|
|
|
function string:get_modname_prefix()
|
|
|
|
local i = self:find(":")
|
|
|
|
if i == 1 then
|
|
|
|
self = self:sub(2, -1)
|
|
|
|
end
|
|
|
|
i = self:find(":")
|
|
|
|
if i then
|
|
|
|
return self:sub(1, i-1)
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-12-02 00:20:05 +06:00
|
|
|
function set_node_instead_air(pos, node)
|
|
|
|
if minetest.env:get_node(pos).name == "air" then
|
|
|
|
minetest.env:set_node(pos, node)
|
|
|
|
end
|
2012-12-02 00:21:00 +06:00
|
|
|
end
|
2012-12-16 21:58:53 +06:00
|
|
|
|
|
|
|
function merge(lhs, rhs)
|
|
|
|
local merged_table = {}
|
|
|
|
for _, v in ipairs(lhs) do
|
|
|
|
table.insert(merged_table, v)
|
|
|
|
end
|
|
|
|
for _, v in ipairs(rhs) do
|
|
|
|
table.insert(merged_table, v)
|
|
|
|
end
|
|
|
|
return merged_table
|
|
|
|
end
|
|
|
|
|
|
|
|
function rshift(x, by)
|
|
|
|
return math.floor(x / 2 ^ by)
|
|
|
|
end
|