/*
InvRef
*/
-InvRef *InvRef::checkobject(lua_State *L, int narg)
+InvRef* InvRef::checkobject(lua_State *L, int narg)
{
luaL_checktype(L, narg, LUA_TUSERDATA);
void *ud = luaL_checkudata(L, narg, className);
- if (!ud)
- luaL_typerror(L, narg, className);
- return *(InvRef **)ud; // unbox pointer
+ if(!ud) luaL_typerror(L, narg, className);
+ return *(InvRef**)ud; // unbox pointer
}
-Inventory *InvRef::getinv(lua_State *L, InvRef *ref)
+Inventory* InvRef::getinv(lua_State *L, InvRef *ref)
{
return getServerInventoryMgr(L)->getInventory(ref->m_loc);
}
-InventoryList *InvRef::getlist(lua_State *L, InvRef *ref, const char *listname)
+InventoryList* InvRef::getlist(lua_State *L, InvRef *ref,
+ const char *listname)
{
NO_MAP_LOCK_REQUIRED;
Inventory *inv = getinv(L, ref);
- if (!inv)
+ if(!inv)
return NULL;
return inv->getList(listname);
}
// Exported functions
// garbage collector
-int InvRef::gc_object(lua_State *L)
-{
+int InvRef::gc_object(lua_State *L) {
InvRef *o = *(InvRef **)(lua_touserdata(L, 1));
delete o;
return 0;
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
InventoryList *list = getlist(L, ref, listname);
- if (list && list->getUsedSlots() > 0) {
+ if(list && list->getUsedSlots() > 0){
lua_pushboolean(L, false);
} else {
lua_pushboolean(L, true);
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
InventoryList *list = getlist(L, ref, listname);
- if (list) {
+ if(list){
lua_pushinteger(L, list->getSize());
} else {
lua_pushinteger(L, 0);
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
InventoryList *list = getlist(L, ref, listname);
- if (list) {
+ if(list){
lua_pushinteger(L, list->getWidth());
} else {
lua_pushinteger(L, 0);
}
Inventory *inv = getinv(L, ref);
- if (inv == NULL) {
+ if(inv == NULL){
lua_pushboolean(L, false);
return 1;
}
- if (newsize == 0) {
+ if(newsize == 0){
inv->deleteList(listname);
reportInventoryChange(L, ref);
lua_pushboolean(L, true);
return 1;
}
InventoryList *list = inv->getList(listname);
- if (list) {
+ if(list){
list->setSize(newsize);
} else {
list = inv->addList(listname, newsize);
- if (!list) {
+ if (!list)
+ {
lua_pushboolean(L, false);
return 1;
}
const char *listname = luaL_checkstring(L, 2);
int newwidth = luaL_checknumber(L, 3);
Inventory *inv = getinv(L, ref);
- if (inv == NULL) {
+ if(inv == NULL){
return 0;
}
InventoryList *list = inv->getList(listname);
- if (list) {
+ if(list){
list->setWidth(newwidth);
} else {
return 0;
int i = luaL_checknumber(L, 3) - 1;
InventoryList *list = getlist(L, ref, listname);
ItemStack item;
- if (list != NULL && i >= 0 && i < (int)list->getSize())
+ if(list != NULL && i >= 0 && i < (int) list->getSize())
item = list->getItem(i);
LuaItemStack::create(L, item);
return 1;
int i = luaL_checknumber(L, 3) - 1;
ItemStack newitem = read_item(L, 4, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
- if (list != NULL && i >= 0 && i < (int)list->getSize()) {
+ if(list != NULL && i >= 0 && i < (int) list->getSize()){
list->changeItem(i, newitem);
reportInventoryChange(L, ref);
lua_pushboolean(L, true);
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
Inventory *inv = getinv(L, ref);
- if (inv) {
+ if(inv){
push_inventory_list(L, inv, listname);
} else {
lua_pushnil(L);
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
Inventory *inv = getinv(L, ref);
- if (inv == NULL) {
+ if(inv == NULL){
return 0;
}
InventoryList *list = inv->getList(listname);
- if (list)
- read_inventory_list(L, 3, inv, listname, getServer(L), list->getSize());
+ if(list)
+ read_inventory_list(L, 3, inv, listname,
+ getServer(L), list->getSize());
else
read_inventory_list(L, 3, inv, listname, getServer(L));
reportInventoryChange(L, ref);
if (!inv) {
return 0;
}
- std::vector<const InventoryList *> lists = inv->getLists();
- std::vector<const InventoryList *>::iterator iter = lists.begin();
+ std::vector<const InventoryList*> lists = inv->getLists();
+ std::vector<const InventoryList*>::iterator iter = lists.begin();
lua_createtable(L, 0, lists.size());
for (; iter != lists.end(); iter++) {
- const char *name = (*iter)->getName().c_str();
+ const char* name = (*iter)->getName().c_str();
lua_pushstring(L, name);
push_inventory_list(L, inv, name);
lua_rawset(L, -3);
const char *listname = luaL_checkstring(L, 2);
ItemStack item = read_item(L, 3, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
- if (list) {
+ if(list){
ItemStack leftover = list->addItem(item);
- if (leftover.count != item.count)
+ if(leftover.count != item.count)
reportInventoryChange(L, ref);
LuaItemStack::create(L, leftover);
} else {
const char *listname = luaL_checkstring(L, 2);
ItemStack item = read_item(L, 3, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
- if (list) {
+ if(list){
lua_pushboolean(L, list->roomForItem(item));
} else {
lua_pushboolean(L, false);
return 1;
}
-// contains_item(self, listname, itemstack or itemstring or table or nil, [match_meta]) ->
-// true/false Returns true if the list contains the given count of the given item
+// contains_item(self, listname, itemstack or itemstring or table or nil, [match_meta]) -> true/false
+// Returns true if the list contains the given count of the given item
int InvRef::l_contains_item(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const char *listname = luaL_checkstring(L, 2);
ItemStack item = read_item(L, 3, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
- if (list) {
+ if(list){
ItemStack removed = list->removeItem(item);
- if (!removed.empty())
+ if(!removed.empty())
reportInventoryChange(L, ref);
LuaItemStack::create(L, removed);
} else {
NO_MAP_LOCK_REQUIRED;
InvRef *ref = checkobject(L, 1);
const InventoryLocation &loc = ref->m_loc;
- switch (loc.type) {
+ switch(loc.type){
case InventoryLocation::PLAYER:
lua_newtable(L);
lua_pushstring(L, "player");
return 1;
}
-InvRef::InvRef(const InventoryLocation &loc) : m_loc(loc)
+
+InvRef::InvRef(const InventoryLocation &loc):
+ m_loc(loc)
{
}
lua_pushliteral(L, "__metatable");
lua_pushvalue(L, methodtable);
- lua_settable(L, metatable); // hide metatable from Lua getmetatable()
+ lua_settable(L, metatable); // hide metatable from Lua getmetatable()
lua_pushliteral(L, "__index");
lua_pushvalue(L, methodtable);
lua_pushcfunction(L, gc_object);
lua_settable(L, metatable);
- lua_pop(L, 1); // drop metatable
+ lua_pop(L, 1); // drop metatable
- luaL_openlib(L, 0, methods, 0); // fill methodtable
- lua_pop(L, 1); // drop methodtable
+ luaL_openlib(L, 0, methods, 0); // fill methodtable
+ lua_pop(L, 1); // drop methodtable
// Cannot be created from Lua
- // lua_register(L, className, create_object);
+ //lua_register(L, className, create_object);
}
const char InvRef::className[] = "InvRef";
-const luaL_Reg InvRef::methods[] = {luamethod(InvRef, is_empty),
- luamethod(InvRef, get_size), luamethod(InvRef, set_size),
- luamethod(InvRef, get_width), luamethod(InvRef, set_width),
- luamethod(InvRef, get_stack), luamethod(InvRef, set_stack),
- luamethod(InvRef, get_list), luamethod(InvRef, set_list),
- luamethod(InvRef, get_lists), luamethod(InvRef, set_lists),
- luamethod(InvRef, add_item), luamethod(InvRef, room_for_item),
- luamethod(InvRef, contains_item), luamethod(InvRef, remove_item),
- luamethod(InvRef, get_location), {0, 0}};
+const luaL_Reg InvRef::methods[] = {
+ luamethod(InvRef, is_empty),
+ luamethod(InvRef, get_size),
+ luamethod(InvRef, set_size),
+ luamethod(InvRef, get_width),
+ luamethod(InvRef, set_width),
+ luamethod(InvRef, get_stack),
+ luamethod(InvRef, set_stack),
+ luamethod(InvRef, get_list),
+ luamethod(InvRef, set_list),
+ luamethod(InvRef, get_lists),
+ luamethod(InvRef, set_lists),
+ luamethod(InvRef, add_item),
+ luamethod(InvRef, room_for_item),
+ luamethod(InvRef, contains_item),
+ luamethod(InvRef, remove_item),
+ luamethod(InvRef, get_location),
+ {0,0}
+};
// get_inventory(location)
int ModApiInventory::l_get_inventory(lua_State *L)
std::string type = luaL_checkstring(L, -1);
lua_pop(L, 1);
- if (type == "node") {
+ if(type == "node"){
MAP_LOCK_REQUIRED;
lua_getfield(L, 1, "pos");
v3s16 pos = check_v3s16(L, -1);
lua_pushnil(L);
return 1;
// END NO_MAP_LOCK_REQUIRED;
+
}
// create_detached_inventory_raw(name, [player_name])
NO_MAP_LOCK_REQUIRED;
const char *name = luaL_checkstring(L, 1);
std::string player = readParam<std::string>(L, 2, "");
- if (getServerInventoryMgr(L)->createDetachedInventory(
- name, getServer(L)->idef(), player) != NULL) {
+ if (getServerInventoryMgr(L)->createDetachedInventory(name, getServer(L)->idef(), player) != NULL) {
InventoryLocation loc;
loc.setDetached(name);
InvRef::create(L, loc);