lua/wrappers/game/lua_map_region.cpp
/**
	 * Sets the map region data from an array table.
	 * The given array table does not have to fit into the map region,
	 * excess values are ignored. And locations past the end of the
	 * given data are left unchanged.
	 *
	 * @param table values The values to set.
	 * @returns am.map_region This.
	 */
Sets the map region data from an array table.
The given array table does not have to fit into the map region,
excess values are ignored. And locations past the end of the
given data are left unchanged.

@param table values The values to set.
Sets the map region data from an array table . The given array table does not have to fit into the map region excess values are ignored . And locations past the end of the given data are left unchanged . @param table values The values to set .
int MapRegion_data(lua_State *lua)
	{
		MapRegion *region = castUData<MapRegion>(lua, 1);
		if (region)
		{
			int args = lua_gettop(lua);
			if (args == 1)
			{
				int pos = 0;
				int total = region->getWidth() * region->getHeight();
				lua_createtable(lua, total, 0);
				int *data = region->getData();
				while (pos < total)
				{
					lua_pushinteger(lua, pos + 1);
					lua_pushinteger(lua, data[pos]);
					lua_settable(lua, -3);
				}
				return 1;
			}
			else if (lua_istable(lua, 2))
			{
				lua_pushnil(lua);
				int pos = 0;
				int total = region->getWidth() * region->getHeight();
				int *data = region->getData();
				while(lua_next(lua, -2) && pos < total)
				{
					data[pos] = lua_tointeger(lua, -1);
					pos++;
					lua_pop(lua, 1);
				}
				lua_first(lua);
			}
			else if (lua_isnum(lua, 2) && lua_isnum(lua, 3))
			{
				int x = lua_tointeger(lua, 2);
				int y = lua_tointeger(lua, 3);
				if (lua_isnum(lua, 4))
				{
					region->setData(x, y, lua_tointeger(lua, 4));
					lua_first(lua);
				}
				else
				{
					int value = 0;
					region->getData(x, y, value);
					lua_pushinteger(lua, value);
					return 1;
				}
			}
			return LuaState::expectedArgs(lua, "data", 3, "integer x, integer y", "integer x, integer y, integer value", "table values");
		}
		return LuaState::expectedContext(lua, "data", "am.map_region");
	}
int MapRegion_data ( lua_State * lua ) { MapRegion * region = castUData < MapRegion > ( lua , 1 ) ; if ( region ) { int args = lua_gettop ( lua ) ; if ( args == 1 ) { int pos = 0 ; int total = region -> getWidth ( ) * region -> getHeight ( ) ; lua_createtable ( lua , total , 0 ) ; int * data = region -> getData ( ) ; while ( pos < total ) { lua_pushinteger ( lua , pos + 1 ) ; lua_pushinteger ( lua , data [ pos ] ) ; lua_settable ( lua , -3 ) ; } return 1 ; } else if ( lua_istable ( lua , 2 ) ) { lua_pushnil ( lua ) ; int pos = 0 ; int total = region -> getWidth ( ) * region -> getHeight ( ) ; int * data = region -> getData ( ) ; while ( lua_next ( lua , -2 ) && pos < total ) { data [ pos ] = lua_tointeger ( lua , -1 ) ; pos ++ ; lua_pop ( lua , 1 ) ; } lua_first ( lua ) ; } else if ( lua_isnum ( lua , 2 ) && lua_isnum ( lua , 3 ) ) { int x = lua_tointeger ( lua , 2 ) ; int y = lua_tointeger ( lua , 3 ) ; if ( lua_isnum ( lua , 4 ) ) { region -> setData ( x , y , lua_tointeger ( lua , 4 ) ) ; lua_first ( lua ) ; } else { int value = 0 ; region -> getData ( x , y , value ) ; lua_pushinteger ( lua , value ) ; return 1 ; } } return LuaState :: expectedArgs ( lua , " " , 3 , " " , " " , " " ) ; } return LuaState :: expectedContext ( lua , " " , " " ) ; }
Sets the map region data from an array table.
Sets the map region data from an array table .
// Returns all // Sets all // Sets x, y value // Gets x, y value