lua/wrappers/game/lua_item.cpp
/**
	 * Sets the item location as being either on the ground, in an inventory or in the player's hand.
	 *
	 * @param string location The location as either "ground", "inventory" or "hand"
	 * @returns am.item This
	 */
Sets the item location as being either on the ground, in an inventory or in the player's hand.
Sets the item location as being either on the ground in an inventory or in the player ' s hand .
int Item_item_location(lua_State *lua)
	{
		Item *item = castUData<Item>(lua, 1);
		if (item)
		{
			if (lua_gettop(lua) == 1)
			{
				const char *name = item->getItemLocationTypeName(item->getItemLocation());
				if (name != nullptr)
				{
					lua_pushstring(lua, name);
					return 1;
				}
				lua_pushnil(lua);
				return 1;
			}
			else
			{
				Item::ItemLocation location = Item::MAX_LENGTH;
				if (lua_isnum(lua, 2))
				{
					location = Item::getItemLocationType(lua_tointeger(lua, 2));
				}
				else if (lua_isstr(lua, 2))
				{
					location = Item::getItemLocationType(lua_tostring(lua, 2));
				}
				else
				{
					return LuaState::expectedArgs(lua, "item_location", 2, "string location_name", "integer location_id");
				}
				if (location != Item::MAX_LENGTH)
				{
					item->setItemLocation(location);
				}
				else
				{
					std::stringstream ss;
					ss << "Unknown item location: ";
					LuaState::printTypeValue(lua, 2, ss);
					LuaState::warning(lua, ss.str().c_str());
				}
				lua_first(lua);
			}
		}
		return LuaState::expectedContext(lua, "item_location", "am.item");
	}
int Item_item_location ( lua_State * lua ) { Item * item = castUData < Item > ( lua , 1 ) ; if ( item ) { if ( lua_gettop ( lua ) == 1 ) { const char * name = item -> getItemLocationTypeName ( item -> getItemLocation ( ) ) ; if ( name != nullptr ) { lua_pushstring ( lua , name ) ; return 1 ; } lua_pushnil ( lua ) ; return 1 ; } else { Item :: ItemLocation location = Item :: MAX_LENGTH ; if ( lua_isnum ( lua , 2 ) ) { location = Item :: getItemLocationType ( lua_tointeger ( lua , 2 ) ) ; } else if ( lua_isstr ( lua , 2 ) ) { location = Item :: getItemLocationType ( lua_tostring ( lua , 2 ) ) ; } else { return LuaState :: expectedArgs ( lua , " " , 2 , " " , " " ) ; } if ( location != Item :: MAX_LENGTH ) { item -> setItemLocation ( location ) ; } else { std :: stringstream ss ; ss << " " ; LuaState :: printTypeValue ( lua , 2 , ss ) ; LuaState :: warning ( lua , ss . str ( ) . c_str ( ) ) ; } lua_first ( lua ) ; } } return LuaState :: expectedContext ( lua , " " , " " ) ; }
Sets the item location as being either on the ground, in an inventory or in the player's hand.
Sets the item location as being either on the ground in an inventory or in the player ' s hand .