本文整理汇总了C++中LuaToNumber函数的典型用法代码示例。如果您正苦于以下问题:C++ LuaToNumber函数的具体用法?C++ LuaToNumber怎么用?C++ LuaToNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LuaToNumber函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LuaError
void PathFinderOutput::Load(lua_State *l)
{
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument in PathFinderOutput::Load");
}
const int args = 1 + lua_rawlen(l, -1);
for (int i = 1; i < args; ++i) {
const char *tag = LuaToString(l, -1, i);
++i;
if (!strcmp(tag, "cycles")) {
this->Cycles = LuaToNumber(l, -1, i);
} else if (!strcmp(tag, "fast")) {
this->Fast = 1;
--i;
} else if (!strcmp(tag, "path")) {
lua_rawgeti(l, -1, i);
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument _");
}
const int subargs = lua_rawlen(l, -1);
for (int k = 0; k < subargs; ++k) {
this->Path[k] = LuaToNumber(l, -1, k + 1);
}
this->Length = subargs;
lua_pop(l, 1);
} else {
LuaError(l, "PathFinderOutput::Load: Unsupported tag: %s" _C_ tag);
}
}
}
示例2: LuaToString
/* virtual */ void CContentTypeLifeBar::Parse(lua_State *l)
{
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
const char *key = LuaToString(l, -2);
if (!strcmp(key, "Variable")) {
const char *const name = LuaToString(l, -1);
this->Index = UnitTypeVar.VariableNameLookup[name];
if (this->Index == -1) {
LuaError(l, "unknown variable '%s'" _C_ name);
}
} else if (!strcmp(key, "Height")) {
this->Height = LuaToNumber(l, -1);
} else if (!strcmp(key, "Width")) {
this->Width = LuaToNumber(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'LifeBar' in DefinePanelContents" _C_ key);
}
}
// Default value and checking errors.
if (this->Height <= 0) {
this->Height = 5; // Default value.
}
if (this->Width <= 0) {
this->Width = 50; // Default value.
}
if (this->Index == -1) {
LuaError(l, "variable undefined for LifeBar");
}
}
示例3: LuaToString
/* virtual */ void Spell_AreaBombardment::Parse(lua_State *l, int startIndex, int endIndex)
{
for (int j = startIndex; j < endIndex; ++j) {
const char *value = LuaToString(l, -1, j + 1);
++j;
if (!strcmp(value, "fields")) {
this->Fields = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "shards")) {
this->Shards = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "damage")) {
this->Damage = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "start-offset-x")) {
this->StartOffsetX = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "start-offset-y")) {
this->StartOffsetY = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "missile")) {
value = LuaToString(l, -1, j + 1);
this->Missile = MissileTypeByIdent(value);
if (this->Missile == NULL) {
DebugPrint("in area-bombardement : missile %s does not exist\n" _C_ value);
}
} else {
LuaError(l, "Unsupported area-bombardment tag: %s" _C_ value);
}
}
// Now, checking value.
if (this->Missile == NULL) {
LuaError(l, "Use a missile for area-bombardment (with missile)");
}
}
示例4: CclGetUnitsAroundUnit
/**
** Get a player's units in rectangle box specified with 2 coordinates
**
** @param l Lua state.
**
** @return Array of units.
*/
static int CclGetUnitsAroundUnit(lua_State *l)
{
const int nargs = lua_gettop(l);
if (nargs != 2 && nargs != 3) {
LuaError(l, "incorrect argument\n");
}
const int slot = LuaToNumber(l, 1);
const CUnit &unit = UnitManager.GetSlotUnit(slot);
const int range = LuaToNumber(l, 2);
bool allUnits = false;
if (nargs == 3) {
allUnits = LuaToBoolean(l, 3);
}
lua_newtable(l);
std::vector<CUnit *> table;
if (allUnits) {
SelectAroundUnit(unit, range, table, HasNotSamePlayerAs(Players[PlayerNumNeutral]));
} else {
SelectAroundUnit(unit, range, table, HasSamePlayerAs(*unit.Player));
}
size_t n = 0;
for (size_t i = 0; i < table.size(); ++i) {
if (table[i]->IsAliveOnMap()) {
lua_pushnumber(l, UnitNumber(*table[i]));
lua_rawseti(l, -2, ++n);
}
}
return 1;
}
示例5: 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;
}
示例6: lua_rawgeti
/* virtual */ bool COrder_Built::ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit)
{
if (!strcmp(value, "worker")) {
++j;
lua_rawgeti(l, -1, j + 1);
this->Worker = CclGetUnitFromRef(l);
lua_pop(l, 1);
} else if (!strcmp(value, "progress")) {
++j;
this->ProgressCounter = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "cancel")) {
this->IsCancelled = true;
} else if (!strcmp(value, "frame")) {
++j;
int frame = LuaToNumber(l, -1, j + 1);
CConstructionFrame *cframe = unit.Type->Construction->Frames;
while (frame-- && cframe->Next != NULL) {
cframe = cframe->Next;
}
this->Frame = cframe;
} else {
return false;
}
return true;
}
示例7: 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;
}
示例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: LuaError
/* static */ void CAnimations::LoadWaitUnitAnim(lua_State *l, CUnit &unit, int luaIndex)
{
if (!lua_istable(l, luaIndex)) {
LuaError(l, "incorrect argument");
}
const int nargs = lua_rawlen(l, luaIndex);
for (int j = 0; j != nargs; ++j) {
const char *value = LuaToString(l, luaIndex, j + 1);
++j;
if (!strcmp(value, "anim-wait")) {
unit.WaitBackup.Wait = LuaToNumber(l, luaIndex, j + 1);
} else if (!strcmp(value, "curr-anim")) {
const int animIndex = LuaToNumber(l, luaIndex, j + 1);
unit.WaitBackup.CurrAnim = AnimationsArray[animIndex];
} else if (!strcmp(value, "anim")) {
const int animIndex = LuaToNumber(l, luaIndex, j + 1);
unit.WaitBackup.Anim = Advance(unit.WaitBackup.CurrAnim, animIndex);
} else if (!strcmp(value, "unbreakable")) {
unit.WaitBackup.Unbreakable = 1;
--j;
} else {
LuaError(l, "Unit anim-data: Unsupported tag: %s" _C_ value);
}
}
}
示例10: lua_rawgeti
/* virtual */ bool COrder_Attack::ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit)
{
if (!strcmp(value, "state")) {
++j;
lua_rawgeti(l, -1, j + 1);
this->State = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "min-range")) {
++j;
lua_rawgeti(l, -1, j + 1);
this->MinRange = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "range")) {
++j;
lua_rawgeti(l, -1, j + 1);
this->Range = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "tile")) {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
lua_pop(l, 1);
} else {
return false;
}
return true;
}
示例11: 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;
}
示例12: CclDefineViewports
/**
** Define the viewports.
**
** @param l Lua state.
*/
static int CclDefineViewports(lua_State *l)
{
int i = 0;
const int args = lua_gettop(l);
for (int j = 0; j < args; ++j) {
const char *value = LuaToString(l, j + 1);
++j;
if (!strcmp(value, "mode")) {
UI.ViewportMode = (ViewportModeType)LuaToNumber(l, j + 1);
} else if (!strcmp(value, "viewport")) {
if (!lua_istable(l, j + 1) && lua_rawlen(l, j + 1) != 3) {
LuaError(l, "incorrect argument");
}
UI.Viewports[i].MapPos.x = LuaToNumber(l, j + 1, 1);
UI.Viewports[i].MapPos.y = LuaToNumber(l, j + 1, 2);
const int slot = LuaToNumber(l, j + 1, 3);
if (slot != -1) {
UI.Viewports[i].Unit = &UnitManager.GetSlotUnit(slot);
}
++i;
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}
}
UI.NumViewports = i;
return 0;
}
示例13: lua_rawgeti
/* virtual */ bool COrder_Build::ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit)
{
if (!strcmp(value, "building")) {
++j;
lua_rawgeti(l, -1, j + 1);
this->BuildingUnit = CclGetUnitFromRef(l);
lua_pop(l, 1);
} else if (!strcmp(value, "range")) {
++j;
this->Range = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "state")) {
++j;
this->State = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "tile")) {
++j;
lua_rawgeti(l, -1, j + 1);
CclGetPos(l, &this->goalPos.x , &this->goalPos.y);
lua_pop(l, 1);
} else if (!strcmp(value, "type")) {
++j;
this->Type = UnitTypeByIdent(LuaToString(l, -1, j + 1));
} else {
return false;
}
return true;
}
示例14: 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;
}
示例15: CclCenterMap
/**
** Center the map.
**
** @param l Lua state.
*/
static int CclCenterMap(lua_State *l)
{
LuaCheckArgs(l, 2);
UI.SelectedViewport->Center(
LuaToNumber(l, 1), LuaToNumber(l, 2), TileSizeX / 2, TileSizeY / 2);
return 0;
}