mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
lua api refactor
This commit is contained in:
parent
5309cbe67f
commit
6bf6e8e011
20 changed files with 663 additions and 710 deletions
46
src/logic/scripting/lua/libitem.cpp
Normal file
46
src/logic/scripting/lua/libitem.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "lua_commons.h"
|
||||
#include "api_lua.h"
|
||||
#include "../scripting.h"
|
||||
#include "../../../content/Content.h"
|
||||
#include "../../../items/ItemDef.h"
|
||||
|
||||
static int l_item_name(lua_State* L) {
|
||||
auto indices = scripting::content->getIndices();
|
||||
lua::luaint id = lua_tointeger(L, 1);
|
||||
if (id < 0 || size_t(id) >= indices->countItemDefs()) {
|
||||
return 0;
|
||||
}
|
||||
auto def = indices->getItemDef(id);
|
||||
lua_pushstring(L, def->name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_item_index(lua_State* L) {
|
||||
auto name = lua_tostring(L, 1);
|
||||
lua_pushinteger(L, scripting::content->requireItem(name).rt.id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_item_stack_size(lua_State* L) {
|
||||
auto indices = scripting::content->getIndices();
|
||||
lua::luaint id = lua_tointeger(L, 1);
|
||||
if (id < 0 || size_t(id) >= indices->countItemDefs()) {
|
||||
return 0;
|
||||
}
|
||||
auto def = indices->getItemDef(id);
|
||||
lua_pushinteger(L, def->stackSize);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_item_defs_count(lua_State* L) {
|
||||
lua_pushinteger(L, scripting::indices->countItemDefs());
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg itemlib [] = {
|
||||
{"index", lua_wrap_errors<l_item_index>},
|
||||
{"name", lua_wrap_errors<l_item_name>},
|
||||
{"stack_size", lua_wrap_errors<l_item_stack_size>},
|
||||
{"defs_count", lua_wrap_errors<l_item_defs_count>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue