lua/wrappers/game/lua_character.cpp
/**
	 * @static
	 * Creates a new character from the character definition.
	 * Character definitions are automatically loaded if one with
	 * the given name is not registered.
	 * <p>Example (a test map Lua file):</p>
	 * <pre>
	 * npc = am.character.from_def("npcs:male1")
	 * if (npc ~= nil)
	 *     npc:name("Fred")
	 * end
	 * </pre>
	 * <p>In "data/defs/npcs.lua":</p>
	 * <pre>
	 * game = am.engine.game()
	 * 
	 * npc = am.character.new()
	 * npc:age(21):gender("male"):graphic(am.sprite.new("characters/npc/front"))
	 * 
	 * -- Here the npc is registered with the name "male1" and "npcs:" will 
	 * -- automatically be prepended because of the filename.
	 * game:char_def("male1", npc) 
	 * </pre>
	 *
	 * @param string def_name The name of the character definition.
	 * @param string [""] game_id The game id to give to the newly created character.
	 * @returns am.character A copy of the character from the given definition, or nil if no definition was found.
	 */
@static
Creates a new character from the character definition.
Character definitions are automatically loaded if one with
the given name is not registered.



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

@param string def_name The name of the character definition.
@param string [""] game_id The game id to give to the newly created character.
@returns am.character A copy of the character from the given definition, or nil if no definition was found.
@static Creates a new character from the character definition . Character definitions are automatically loaded if one with the given name is not registered . Here the npc is registered with the name " male1 " and " npcs : " will automatically be prepended because of the filename . @param string def_name The name of the character definition . @param string [ " " ] game_id The game id to give to the newly created character . @returns am . character A copy of the character from the given definition or nil if no definition was found .
int Character_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)
			{
				Character *def = game->getCharDefinition(lua_tostring(lua, 1));
				if (def)
				{
					Character *newChar = new Character(*def);
					if (lua_isstr(lua, 2))
					{
						newChar->setGameId(lua_tostring(lua, 2));
					}
					wrapRefObject<Character>(lua, newChar);
					return 1;
				}
				std::stringstream ss;
				ss << "No character 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, string [\"\"] game_id");
	}
int Character_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 ) { Character * def = game -> getCharDefinition ( lua_tostring ( lua , 1 ) ) ; if ( def ) { Character * newChar = new Character ( * def ) ; if ( lua_isstr ( lua , 2 ) ) { newChar -> setGameId ( lua_tostring ( lua , 2 ) ) ; } wrapRefObject < Character > ( lua , newChar ) ; 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 character from the character definition.
@static Creates a new character from the character definition .