Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
a9c0961e
Commit
a9c0961e
authored
11 years ago
by
PilzAdam
Browse files
Options
Downloads
Patches
Plain Diff
Add set_name(), set_count(), set_wear() and set_metadata() to Lua ItemStack
parent
73139286
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/lua_api.txt
+4
-0
4 additions, 0 deletions
doc/lua_api.txt
src/script/lua_api/l_item.cpp
+63
-0
63 additions, 0 deletions
src/script/lua_api/l_item.cpp
src/script/lua_api/l_item.h
+12
-0
12 additions, 0 deletions
src/script/lua_api/l_item.h
with
79 additions
and
0 deletions
doc/lua_api.txt
+
4
−
0
View file @
a9c0961e
...
...
@@ -1658,9 +1658,13 @@ ItemStack: A stack of items.
methods:
- is_empty(): return true if stack is empty
- get_name(): returns item name (e.g. "default:stone")
- set_name(itemname)
- get_count(): returns number of items on the stack
- set_count(count)
- get_wear(): returns tool wear (0-65535), 0 for non-tools
- set_wear(wear)
- get_metadata(): returns metadata (a string attached to an item stack)
- set_metadata(metadata)
- clear(): removes all items from the stack, making it empty
- replace(item): replace the contents of this stack (item can also
be an itemstring or table)
...
...
This diff is collapsed.
Click to expand it.
src/script/lua_api/l_item.cpp
+
63
−
0
View file @
a9c0961e
...
...
@@ -57,6 +57,20 @@ int LuaItemStack::l_get_name(lua_State *L)
return
1
;
}
// set_name(self, name)
int
LuaItemStack
::
l_set_name
(
lua_State
*
L
)
{
NO_MAP_LOCK_REQUIRED
;
LuaItemStack
*
o
=
checkobject
(
L
,
1
);
ItemStack
&
item
=
o
->
m_stack
;
item
.
name
=
luaL_checkstring
(
L
,
2
);
if
(
item
.
name
==
""
||
item
.
empty
())
item
.
clear
();
return
1
;
}
// get_count(self) -> number
int
LuaItemStack
::
l_get_count
(
lua_State
*
L
)
{
...
...
@@ -67,6 +81,20 @@ int LuaItemStack::l_get_count(lua_State *L)
return
1
;
}
// set_count(self, number)
int
LuaItemStack
::
l_set_count
(
lua_State
*
L
)
{
NO_MAP_LOCK_REQUIRED
;
LuaItemStack
*
o
=
checkobject
(
L
,
1
);
ItemStack
&
item
=
o
->
m_stack
;
item
.
count
=
luaL_checkinteger
(
L
,
2
);
if
(
item
.
name
==
""
||
item
.
empty
())
item
.
clear
();
return
1
;
}
// get_wear(self) -> number
int
LuaItemStack
::
l_get_wear
(
lua_State
*
L
)
{
...
...
@@ -77,6 +105,20 @@ int LuaItemStack::l_get_wear(lua_State *L)
return
1
;
}
// set_wear(self, number)
int
LuaItemStack
::
l_set_wear
(
lua_State
*
L
)
{
NO_MAP_LOCK_REQUIRED
;
LuaItemStack
*
o
=
checkobject
(
L
,
1
);
ItemStack
&
item
=
o
->
m_stack
;
item
.
wear
=
luaL_checkinteger
(
L
,
2
);
if
(
item
.
wear
>
65535
)
item
.
clear
();
return
1
;
}
// get_metadata(self) -> string
int
LuaItemStack
::
l_get_metadata
(
lua_State
*
L
)
{
...
...
@@ -87,6 +129,23 @@ int LuaItemStack::l_get_metadata(lua_State *L)
return
1
;
}
// set_metadata(self, string)
int
LuaItemStack
::
l_set_metadata
(
lua_State
*
L
)
{
NO_MAP_LOCK_REQUIRED
;
LuaItemStack
*
o
=
checkobject
(
L
,
1
);
ItemStack
&
item
=
o
->
m_stack
;
size_t
len
=
0
;
const
char
*
ptr
=
luaL_checklstring
(
L
,
2
,
&
len
);
if
(
ptr
)
item
.
metadata
.
assign
(
ptr
,
len
);
else
item
.
metadata
=
""
;
return
1
;
}
// clear(self) -> true
int
LuaItemStack
::
l_clear
(
lua_State
*
L
)
{
...
...
@@ -363,9 +422,13 @@ const char LuaItemStack::className[] = "ItemStack";
const
luaL_reg
LuaItemStack
::
methods
[]
=
{
luamethod
(
LuaItemStack
,
is_empty
),
luamethod
(
LuaItemStack
,
get_name
),
luamethod
(
LuaItemStack
,
set_name
),
luamethod
(
LuaItemStack
,
get_count
),
luamethod
(
LuaItemStack
,
set_count
),
luamethod
(
LuaItemStack
,
get_wear
),
luamethod
(
LuaItemStack
,
set_wear
),
luamethod
(
LuaItemStack
,
get_metadata
),
luamethod
(
LuaItemStack
,
set_metadata
),
luamethod
(
LuaItemStack
,
clear
),
luamethod
(
LuaItemStack
,
replace
),
luamethod
(
LuaItemStack
,
to_string
),
...
...
This diff is collapsed.
Click to expand it.
src/script/lua_api/l_item.h
+
12
−
0
View file @
a9c0961e
...
...
@@ -41,15 +41,27 @@ class LuaItemStack : public ModApiBase {
// get_name(self) -> string
static
int
l_get_name
(
lua_State
*
L
);
// set_name(self, name)
static
int
l_set_name
(
lua_State
*
L
);
// get_count(self) -> number
static
int
l_get_count
(
lua_State
*
L
);
// set_count(self, number)
static
int
l_set_count
(
lua_State
*
L
);
// get_wear(self) -> number
static
int
l_get_wear
(
lua_State
*
L
);
// set_wear(self, number)
static
int
l_set_wear
(
lua_State
*
L
);
// get_metadata(self) -> string
static
int
l_get_metadata
(
lua_State
*
L
);
// set_metadata(self, string)
static
int
l_set_metadata
(
lua_State
*
L
);
// clear(self) -> true
static
int
l_clear
(
lua_State
*
L
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment