lua/wrappers/game/lua_item.cpp
/**
	 * @static
	 * Creates a new item from the item definition.
	 * Item definitions are automatically loaded if one with
	 * the given name is not registered.
	 * <p>Example (a test map Lua file):</p>
	 * <pre>
	 * item = am.item.from_def("wooden:sword")
	 * if (item ~= nil)
	 *     item:name("Fred's Sword")
	 * end
	 * </pre>
	 * <p>In "data/defs/wooden.lua":</p>
	 * <pre>
	 * game = am.engine.game()
	 * 
	 * item = am.item.new()
	 * item:item_type("sword")
	 *     :graphic(am.sprite.new("item/sword"))
	 *     :groundGraphic(am.sprite.new("item/swordGround"))
	 * 
	 * -- Here the npc is registered with the name "sword" and "wooden:" will 
	 * -- automatically be prepended because of the filename.
	 * game:item_def("sword", item) 
	 * </pre>
	 *
	 * @param string def_name The name of the item definition.
	 * @returns Item A copy of the item from the given definition, or nil if no definition was found.
	 */
@static
Creates a new item from the item definition.
Item definitions are automatically loaded if one with
the given name is not registered.



Here the npc is registered with the name "sword" and "wooden:" will
automatically be prepended because of the filename.

@param string def_name The name of the item definition.
@returns Item A copy of the item from the given definition, or nil if no definition was found.
@static Creates a new item from the item definition . Item definitions are automatically loaded if one with the given name is not registered . Here the npc is registered with the name " sword " and " wooden : " will automatically be prepended because of the filename . @param string def_name The name of the item definition . @returns Item A copy of the item from the given definition or nil if no definition was found .
int Item_from_def(lua_State *lua)
	{
		int args = lua_gettop(lua);
		if (lua_isstr(lua, 1) && (args == 1 || args > 1 && lua_isstr(lua, 2)))
		{
			Game *game = Engine::getGame();
			if (game)
			{
				Item *def = game->getItemDefinition(lua_tostring(lua, 1));
				if (def)
				{
					Item *newItem = new Item(*def);
					wrapRefObject<Item>(lua, newItem);
					return 1;
				}
				std::stringstream ss;
				ss << "No item with the definition '" << lua_tostring(lua, 1) << "' was found.";
				LuaState::warning(lua, ss.str().c_str());
				lua_pushnil(lua);
				return 1;
			}
			std::stringstream ss;
			ss << "Unable to get definition (" << lua_tostring(lua, 1) << " when a game is not running";
			LuaState::warning(lua, ss.str().c_str());
			lua_pushnil(lua);
			return 1;
		}
		return LuaState::expectedArgs(lua, "@from_def", "string def_name");
	}
int Item_from_def ( lua_State * lua ) { int args = lua_gettop ( lua ) ; if ( lua_isstr ( lua , 1 ) && ( args == 1 || args > 1 && lua_isstr ( lua , 2 ) ) ) { Game * game = Engine :: getGame ( ) ; if ( game ) { Item * def = game -> getItemDefinition ( lua_tostring ( lua , 1 ) ) ; if ( def ) { Item * newItem = new Item ( * def ) ; wrapRefObject < Item > ( lua , newItem ) ; return 1 ; } std :: stringstream ss ; ss << " " << lua_tostring ( lua , 1 ) << " " ; LuaState :: warning ( lua , ss . str ( ) . c_str ( ) ) ; lua_pushnil ( lua ) ; return 1 ; } std :: stringstream ss ; ss << " " << lua_tostring ( lua , 1 ) << " " ; LuaState :: warning ( lua , ss . str ( ) . c_str ( ) ) ; lua_pushnil ( lua ) ; return 1 ; } return LuaState :: expectedArgs ( lua , " " , " " ) ; }
@static
 Creates a new item from the item definition.
@static Creates a new item from the item definition .