本文整理汇总了C++中LuaCheckArgs函数的典型用法代码示例。如果您正苦于以下问题:C++ LuaCheckArgs函数的具体用法?C++ LuaCheckArgs怎么用?C++ LuaCheckArgs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LuaCheckArgs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CclNewPlayerColors
/**
** Make new player colors
**
** @param l Lua state.
*/
static int CclNewPlayerColors(lua_State *l)
{
LuaCheckArgs(l, 0);
SetPlayersPalette();
return 0;
}
示例2: CclSavedGameInfo
/**
** Load the SavedGameInfo Header
**
** @param l Lua state.
*/
static int CclSavedGameInfo(lua_State *l)
{
const char *value;
LuaCheckArgs(l, 1);
LuaCheckTable(l, 1);
lua_pushnil(l);
while (lua_next(l, 1)) {
value = LuaToString(l, -2);
if (!strcmp(value, "SaveFile")) {
if (strcpy_s(CurrentMapPath, sizeof(CurrentMapPath), LuaToString(l, -1)) != 0) {
LuaError(l, "SaveFile too long");
}
std::string buf = StratagusLibPath;
buf += "/";
buf += LuaToString(l, -1);
if (LuaLoadFile(buf) == -1) {
DebugPrint("Load failed: %s\n" _C_ value);
}
} else if (!strcmp(value, "SyncHash")) {
SyncHash = LuaToNumber(l, -1);
} else if (!strcmp(value, "SyncRandSeed")) {
SyncRandSeed = LuaToNumber(l, -1);
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}
lua_pop(l, 1);
}
return 0;
}
示例3: CclKillUnit
/**
** Kill a unit
**
** @param l Lua state.
**
** @return Returns true if a unit was killed.
*/
static int CclKillUnit(lua_State *l)
{
LuaCheckArgs(l, 2);
lua_pushvalue(l, 1);
const CUnitType *unittype = TriggerGetUnitType(l);
lua_pop(l, 1);
const int plynr = TriggerGetPlayer(l);
if (plynr == -1) {
CUnitManager::Iterator it = std::find_if(UnitManager.begin(), UnitManager.end(), HasSameUnitTypeAs(unittype));
if (it != UnitManager.end()) {
LetUnitDie(**it);
lua_pushboolean(l, 1);
return 1;
}
} else {
CPlayer &player = Players[plynr];
std::vector<CUnit *>::iterator it = std::find_if(player.UnitBegin(), player.UnitEnd(), HasSameUnitTypeAs(unittype));
if (it != player.UnitEnd()) {
LetUnitDie(**it);
lua_pushboolean(l, 1);
return 1;
}
}
lua_pushboolean(l, 0);
return 1;
}
示例4: CclMakeSound
/**
** Create a sound.
**
** Glue between c and scheme. This function asks the sound system to
** register a sound under a given name, wiht an associated list of files
** (the list can be replaced by only one file).
**
** @param l Lua state.
**
** @return the sound id of the created sound
*/
static int CclMakeSound(lua_State *l)
{
LuaCheckArgs(l, 2);
std::string c_name = LuaToString(l, 1);
std::vector<std::string> files;
CSound *id;
if (lua_isstring(l, 2)) {
// only one file
files.push_back(LuaToString(l, 2));
id = MakeSound(c_name, files);
} else if (lua_istable(l, 2)) {
// several files
const int args = lua_rawlen(l, 2);
files.reserve(args);
for (int j = 0; j < args; ++j) {
lua_rawgeti(l, 2, j + 1);
files.push_back(LuaToString(l, -1));
lua_pop(l, 1);
}
id = MakeSound(c_name, files);
} else {
LuaError(l, "string or table expected");
return 0;
}
LuaUserData *data = (LuaUserData *)lua_newuserdata(l, sizeof(LuaUserData));
data->Type = LuaSoundType;
data->Data = id;
return 1;
}
示例5: CclSetEditorStartUnit
/**
** Set the editor's start location unit
**
** @param l Lua state.
*/
static int CclSetEditorStartUnit(lua_State *l)
{
LuaCheckArgs(l, 1);
delete[] Editor.StartUnitName;
Editor.StartUnitName = new_strdup(LuaToString(l, 1));
return 0;
}
示例6: CclBuildTilesetTables
/**
** Build tileset tables like humanWallTable or mixedLookupTable
**
** Called after DefineTileset and only for tilesets that have wall,
** trees and rocks. This function will be deleted when removing
** support of walls and alike in the tileset.
*/
static int CclBuildTilesetTables(lua_State *l)
{
LuaCheckArgs(l, 0);
Map.Tileset->buildTable(l);
return 0;
}
示例7: CclGetVideoResolution
/**
** Get the video resolution.
**
** @param l Lua state.
*/
static int CclGetVideoResolution(lua_State *l)
{
LuaCheckArgs(l, 0);
lua_pushnumber(l, Video.Width);
lua_pushnumber(l, Video.Height);
return 2;
}
示例8: CclShowMapLocation
/**
** Show Map Location
**
** @param l Lua state.
*/
static int CclShowMapLocation(lua_State *l)
{
// Put a unit on map, use its properties, except for
// what is listed below
LuaCheckArgs(l, 4);
const char *unitname = LuaToString(l, 5);
CUnitType *unitType = UnitTypeByIdent(unitname);
if (!unitType) {
DebugPrint("Unable to find UnitType '%s'" _C_ unitname);
return 0;
}
CUnit *target = MakeUnit(*unitType, ThisPlayer);
if (target != NULL) {
target->Variable[HP_INDEX].Value = 0;
target->tilePos.x = LuaToNumber(l, 1);
target->tilePos.y = LuaToNumber(l, 2);
target->TTL = GameCycle + LuaToNumber(l, 4);
target->CurrentSightRange = LuaToNumber(l, 3);
//Wyrmgus start
UpdateUnitSightRange(*target);
//Wyrmgus end
MapMarkUnitSight(*target);
} else {
DebugPrint("Unable to allocate Unit");
}
return 0;
}
示例9: CclCheckDependency
/**
** Checks if dependencies are met.
**
** @return true if the dependencies are met.
**
** @param l Lua state.
** Argument 1: player
** Argument 2: object which we want to check the dependencies of
*/
static int CclCheckDependency(lua_State *l)
{
LuaCheckArgs(l, 2);
const char *object = LuaToString(l, 2);
lua_pop(l, 1);
const int plynr = TriggerGetPlayer(l);
if (plynr == -1) {
LuaError(l, "bad player: %i" _C_ plynr);
}
const CPlayer *player = &Players[plynr];
if (!strncmp(object, "unit-", 5)) {
const CUnitType *unit_type = UnitTypeByIdent(object);
if (!unit_type) {
LuaError(l, "Invalid unit type: \"%s\"" _C_ object);
}
lua_pushboolean(l, CheckDependencies(unit_type, player));
} else if (!strncmp(object, "upgrade-", 8)) {
const CUpgrade *upgrade = CUpgrade::Get(object);
if (!upgrade) {
LuaError(l, "Invalid upgrade: \"%s\"" _C_ object);
}
lua_pushboolean(l, CheckDependencies(upgrade, player));
} else {
LuaError(l, "Invalid target of dependency check: \"%s\"" _C_ object);
}
return 1;
}
示例10: CclGroup
/**
** Define the group.
**
** @param l Lua state.
*/
static int CclGroup(lua_State *l)
{
int i;
CUnitGroup *grp;
int args;
int j;
LuaCheckArgs(l, 3);
InitGroups();
grp = &Groups[(int)LuaToNumber(l, 1)];
grp->NumUnits = LuaToNumber(l, 2);
i = 0;
args = lua_objlen(l, 3);
for (j = 0; j < args; ++j) {
const char *str;
lua_rawgeti(l, 3, j + 1);
str = LuaToString(l, -1);
lua_pop(l, 1);
grp->Units[i++] = UnitSlots[strtol(str + 1, NULL, 16)];
}
return 0;
}
示例11: CclDefineMapSetup
/**
** Define the lua file that will build the map
**
** @param l Lua state.
*/
static int CclDefineMapSetup(lua_State *l)
{
LuaCheckArgs(l, 1);
Map.Info.Filename = LuaToString(l, 1);
return 0;
}
示例12: CclGetTileTerrainHasFlag
/**
** Check if the tile's terrain has a particular flag.
**
** @param l Lua state.
**
** @return True if has the flag, false if not.
*/
static int CclGetTileTerrainHasFlag(lua_State *l)
{
LuaCheckArgs(l, 3);
const Vec2i pos(LuaToNumber(l, 1), LuaToNumber(l, 2));
//Wyrmgus start
if (pos.x < 0 || pos.x >= Map.Info.MapWidth || pos.y < 0 || pos.y >= Map.Info.MapHeight) {
lua_pushboolean(l, 0);
return 1;
}
// unsigned short flag = 0;
unsigned long flag = 0;
//Wyrmgus end
const char *flag_name = LuaToString(l, 3);
if (!strcmp(flag_name, "water")) {
flag = MapFieldWaterAllowed;
} else if (!strcmp(flag_name, "land")) {
flag = MapFieldLandAllowed;
} else if (!strcmp(flag_name, "coast")) {
flag = MapFieldCoastAllowed;
} else if (!strcmp(flag_name, "no-building")) {
flag = MapFieldNoBuilding;
} else if (!strcmp(flag_name, "unpassable")) {
flag = MapFieldUnpassable;
//Wyrmgus start
} else if (!strcmp(flag_name, "air-unpassable")) {
flag = MapFieldAirUnpassable;
} else if (!strcmp(flag_name, "dirt")) {
flag = MapFieldDirt;
} else if (!strcmp(flag_name, "grass")) {
flag = MapFieldGrass;
} else if (!strcmp(flag_name, "gravel")) {
flag = MapFieldGravel;
} else if (!strcmp(flag_name, "mud")) {
flag = MapFieldMud;
} else if (!strcmp(flag_name, "stone-floor")) {
flag = MapFieldStoneFloor;
} else if (!strcmp(flag_name, "stumps")) {
flag = MapFieldStumps;
//Wyrmgus end
} else if (!strcmp(flag_name, "wall")) {
flag = MapFieldWall;
} else if (!strcmp(flag_name, "rock")) {
flag = MapFieldRocks;
} else if (!strcmp(flag_name, "forest")) {
flag = MapFieldForest;
}
const CMapField &mf = *Map.Field(pos);
if (mf.getFlag() & flag) {
lua_pushboolean(l, 1);
} else {
lua_pushboolean(l, 0);
}
return 1;
}
示例13: CclDefinePlayerColors
/**
** Define player colors
**
** @param l Lua state.
*/
static int CclDefinePlayerColors(lua_State *l)
{
LuaCheckArgs(l, 1);
if (!lua_istable(l, 1)) {
LuaError(l, "incorrect argument");
}
const int args = lua_rawlen(l, 1);
for (int i = 0; i < args; ++i) {
PlayerColorNames[i / 2] = LuaToString(l, 1, i + 1);
++i;
lua_rawgeti(l, 1, i + 1);
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
const int numcolors = lua_rawlen(l, -1);
if (numcolors != PlayerColorIndexCount) {
LuaError(l, "You should use %d colors (See DefinePlayerColorIndex())" _C_ PlayerColorIndexCount);
}
for (int j = 0; j < numcolors; ++j) {
lua_rawgeti(l, -1, j + 1);
PlayerColorsRGB[i / 2][j].Parse(l);
lua_pop(l, 1);
}
}
return 0;
}
示例14: CclSetMetaServer
/**
** Set the metaserver to use for internet play.
**
** @param l Lua state.
*/
int CclSetMetaServer(lua_State *l)
{
LuaCheckArgs(l, 2);
MasterHost = LuaToString(l, 1);
MasterPort = LuaToNumber(l, 2);
return 0;
}
示例15: CclCenterMap
/**
** Center the map.
**
** @param l Lua state.
*/
static int CclCenterMap(lua_State *l)
{
LuaCheckArgs(l, 2);
const Vec2i pos(LuaToNumber(l, 1), LuaToNumber(l, 2));
UI.SelectedViewport->Center(Map.TilePosToMapPixelPos_Center(pos));
return 0;
}