-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
43 lines (36 loc) · 1.06 KB
/
api.lua
File metadata and controls
43 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- Alternode API
--
-- @topic api
local S = core.get_translator(alternode.modname)
--- Retrieves node meta value of a given key.
--
-- @function alternode.get
-- @tparam table pos Position of node.
-- @tparam string key Key to check for in node meta.
-- @treturn string Value of key.
function alternode.get(pos, key)
return core.get_meta(pos):get_string(key)
end
--- Sets node meta value of a given key.
--
-- @function alternode.set
-- @tparam table pos Position of node.
-- @tparam string key Key to be set.
-- @tparam string value Value to be set for `key`.
-- @treturn bool `true` if succeeded.
function alternode.set(pos, key, value)
local meta = core.get_meta(pos)
meta:set_string(key, value)
return meta:get_string(key) == value
end
--- Unsets node meta value of a given key.
--
-- @function alternode.unset
-- @tparam table pos Position of node.
-- @tparam string key Key to be unset.
-- @treturn bool `true` if succeeded.
function alternode.unset(pos, key)
local meta = core.get_meta(pos)
meta:set_string(key, nil)
return meta:get_string(key) == ""
end