本文整理汇总了C++中LuaError函数的典型用法代码示例。如果您正苦于以下问题:C++ LuaError函数的具体用法?C++ LuaError怎么用?C++ LuaError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LuaError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: luaL_checktype
// register_item_raw({lots of stuff})
int ModApiItemMod::l_register_item_raw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
luaL_checktype(L, 1, LUA_TTABLE);
int table = 1;
// Get the writable item and node definition managers from the server
IWritableItemDefManager *idef =
getServer(L)->getWritableItemDefManager();
IWritableNodeDefManager *ndef =
getServer(L)->getWritableNodeDefManager();
// Check if name is defined
std::string name;
lua_getfield(L, table, "name");
if(lua_isstring(L, -1)){
name = lua_tostring(L, -1);
verbosestream<<"register_item_raw: "<<name<<std::endl;
} else {
throw LuaError("register_item_raw: name is not defined or not a string");
}
// Check if on_use is defined
ItemDefinition def;
// Set a distinctive default value to check if this is set
def.node_placement_prediction = "__default";
// Read the item definition
def = read_item_definition(L, table, def);
// Default to having client-side placement prediction for nodes
// ("" in item definition sets it off)
if(def.node_placement_prediction == "__default"){
if(def.type == ITEM_NODE)
def.node_placement_prediction = name;
else
def.node_placement_prediction = "";
}
// Register item definition
idef->registerItem(def);
// Read the node definition (content features) and register it
if(def.type == ITEM_NODE){
const ContentFeatures &f = read_content_features(L, table);
content_t id = ndef->set(f.name, f);
if(id > MAX_REGISTERED_CONTENT){
throw LuaError("Number of registerable nodes ("
+ itos(MAX_REGISTERED_CONTENT+1)
+ ") exceeded (" + name + ")");
}
}
return 0; /* number of results */
}
示例2: CclSpellAutocast
/**
** Parse the Condition for spell.
**
** @param l Lua state.
** @param autocast pointer to autocast to fill with data.
**
** @note: autocast must be allocated. All data already in is LOST.
*/
static void CclSpellAutocast(lua_State *l, AutoCastInfo *autocast)
{
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
const int args = lua_rawlen(l, -1);
for (int j = 0; j < args; ++j) {
const char *value = LuaToString(l, -1, j + 1);
++j;
if (!strcmp(value, "range")) {
autocast->Range = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "min-range")) {
autocast->MinRange = LuaToNumber(l, -1, j + 1);
} else if (!strcmp(value, "position-autocast")) {
lua_rawgeti(l, -1, j + 1);
autocast->PositionAutoCast = new LuaCallback(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "combat")) {
autocast->Combat = Ccl2Condition(l, LuaToString(l, -1, j + 1));
} else if (!strcmp(value, "attacker")) {
autocast->Attacker = Ccl2Condition(l, LuaToString(l, -1, j + 1));
} else if (!strcmp(value, "corpse")) {
autocast->Corpse = Ccl2Condition(l, LuaToString(l, -1, j + 1));
} else if (!strcmp(value, "priority")) {
lua_rawgeti(l, -1, j + 1);
if (!lua_istable(l, -1) || lua_rawlen(l, -1) != 2) {
LuaError(l, "incorrect argument");
}
lua_rawgeti(l, -1, 1);
std::string var = LuaToString(l, -1);
int index = UnitTypeVar.VariableNameLookup[var.c_str()];// User variables
if (index == -1) {
if (!strcmp(var.c_str(), "Distance")) {
index = ACP_DISTANCE;
} else {
fprintf(stderr, "Bad variable name '%s'\n", var.c_str());
Exit(1);
}
}
autocast->PriorytyVar = index;
lua_pop(l, 1);
autocast->ReverseSort = LuaToBoolean(l, -1, 2);
lua_pop(l, 1);
} else if (!strcmp(value, "condition")) {
if (!autocast->Condition) {
autocast->Condition = new ConditionInfo;
}
lua_rawgeti(l, -1, j + 1);
CclSpellCondition(l, autocast->Condition);
lua_pop(l, 1);
} else {
LuaError(l, "Unsupported autocast tag: %s" _C_ value);
}
}
}
示例3: CclGetWorldData
/**
** Get world data.
**
** @param l Lua state.
*/
static int CclGetWorldData(lua_State *l)
{
if (lua_gettop(l) < 2) {
LuaError(l, "incorrect argument");
}
std::string world_ident = LuaToString(l, 1);
CWorld *world = CWorld::GetWorld(world_ident);
if (!world) {
LuaError(l, "World \"%s\" doesn't exist." _C_ world_ident.c_str());
}
const char *data = LuaToString(l, 2);
if (!strcmp(data, "Name")) {
lua_pushstring(l, world->Name.c_str());
return 1;
} else if (!strcmp(data, "ID")) {
lua_pushnumber(l, world->ID);
return 1;
} else if (!strcmp(data, "Description")) {
lua_pushstring(l, world->Description.c_str());
return 1;
} else if (!strcmp(data, "Background")) {
lua_pushstring(l, world->Background.c_str());
return 1;
} else if (!strcmp(data, "Quote")) {
lua_pushstring(l, world->Quote.c_str());
return 1;
} else if (!strcmp(data, "Plane")) {
if (world->Plane) {
lua_pushstring(l, world->Plane->Ident.c_str());
} else {
lua_pushstring(l, "");
}
return 1;
} else if (!strcmp(data, "Provinces")) {
lua_createtable(l, world->Provinces.size(), 0);
for (size_t i = 1; i <= world->Provinces.size(); ++i)
{
lua_pushstring(l, world->Provinces[i-1]->Name.c_str());
lua_rawseti(l, -2, i);
}
return 1;
} else if (!strcmp(data, "Species")) {
lua_createtable(l, world->Species.size(), 0);
for (size_t i = 1; i <= world->Species.size(); ++i)
{
lua_pushstring(l, world->Species[i-1]->Ident.c_str());
lua_rawseti(l, -2, i);
}
return 1;
} else {
LuaError(l, "Invalid field: %s" _C_ data);
}
return 0;
}
示例4: CclCreateMissile
/**
** Create a missile on the map
**
** @param l Lua state.
**
*/
static int CclCreateMissile(lua_State *l)
{
LuaCheckArgs(l, 6);
const std::string name = LuaToString(l, 1);
const MissileType *mtype = MissileTypeByIdent(name);
if (!mtype) {
LuaError(l, "Bad missile");
}
PixelPos startpos, endpos;
if (!lua_istable(l, 2) || lua_rawlen(l, 2) != 2) {
LuaError(l, "incorrect argument !!");
}
lua_rawgeti(l, 2, 1);
startpos.x = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, 2, 2);
startpos.y = LuaToNumber(l, -1);
lua_pop(l, 1);
if (!lua_istable(l, 3) || lua_rawlen(l, 3) != 2) {
LuaError(l, "incorrect argument !!");
}
lua_rawgeti(l, 3, 1);
endpos.x = LuaToNumber(l, -1);
lua_pop(l, 1);
lua_rawgeti(l, 3, 2);
endpos.y = LuaToNumber(l, -1);
lua_pop(l, 1);
const int sourceUnitId = LuaToNumber(l, 4);
const int destUnitId = LuaToNumber(l, 5);
const bool dealDamage = LuaToBoolean(l, 6);
CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager.GetSlotUnit(sourceUnitId) : NULL;
CUnit *destUnit = destUnitId != -1 ? &UnitManager.GetSlotUnit(destUnitId) : NULL;
if (sourceUnit != NULL) {
startpos += sourceUnit->GetMapPixelPosTopLeft();
}
if (destUnit != NULL) {
endpos += destUnit->GetMapPixelPosTopLeft();
}
Missile *missile = MakeMissile(*mtype, startpos, endpos);
if (!missile) {
return 0;
}
if (dealDamage) {
missile->SourceUnit = sourceUnit;
}
missile->TargetUnit = destUnit;
return 0;
}
示例5: LuaError
void CMapField::parse(lua_State *l)
{
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
const int len = lua_rawlen(l, -1);
if (len < 4) {
LuaError(l, "incorrect argument");
}
this->tile = LuaToNumber(l, -1, 1);
this->playerInfo.SeenTile = LuaToNumber(l, -1, 2);
this->Value = LuaToNumber(l, -1, 3);
this->cost = LuaToNumber(l, -1, 4);
for (int j = 4; j < len; ++j) {
const char *value = LuaToString(l, -1, j + 1);
if (!strcmp(value, "explored")) {
++j;
this->playerInfo.Visible[LuaToNumber(l, -1, j + 1)] = 1;
} else if (!strcmp(value, "human")) {
this->Flags |= MapFieldHuman;
} else if (!strcmp(value, "land")) {
this->Flags |= MapFieldLandAllowed;
} else if (!strcmp(value, "coast")) {
this->Flags |= MapFieldCoastAllowed;
} else if (!strcmp(value, "water")) {
this->Flags |= MapFieldWaterAllowed;
} else if (!strcmp(value, "mud")) {
this->Flags |= MapFieldNoBuilding;
} else if (!strcmp(value, "block")) {
this->Flags |= MapFieldUnpassable;
} else if (!strcmp(value, "wall")) {
this->Flags |= MapFieldWall;
} else if (!strcmp(value, "rock")) {
this->Flags |= MapFieldRocks;
} else if (!strcmp(value, "wood")) {
this->Flags |= MapFieldForest;
} else if (!strcmp(value, "ground")) {
this->Flags |= MapFieldLandUnit;
} else if (!strcmp(value, "air")) {
this->Flags |= MapFieldAirUnit;
} else if (!strcmp(value, "sea")) {
this->Flags |= MapFieldSeaUnit;
} else if (!strcmp(value, "building")) {
this->Flags |= MapFieldBuilding;
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}
}
}
示例6: LuaWear_Event
void LuaWear_Event(const LLUUID& assetid)
{
LLWearable *wear=LuaLoadWearable(assetid);
if(!wear)
LuaError("No Wearable found");
else if((wear=gWearableList.createCopy(wear))==NULL)
LuaError("Failed creation of new wearable");
else
{
wear->saveNewAsset();
wear->writeToAvatar(false);
}
}
示例7: CclSpellMissileLocation
/**
** Parse the missile location description for a spell action.
**
** @param l Lua state.
** @param location Pointer to missile location description.
**
** @note This is only here to avoid code duplication. You don't have
** any reason to USE this:)
*/
static void CclSpellMissileLocation(lua_State *l, SpellActionMissileLocation *location)
{
const char *value;
int args;
int j;
Assert(location != NULL);
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
args = lua_objlen(l, -1);
j = 0;
for (j = 0; j < args; ++j) {
lua_rawgeti(l, -1, j + 1);
value = LuaToString(l, -1);
lua_pop(l, 1);
++j;
if (!strcmp(value, "base")) {
lua_rawgeti(l, -1, j + 1);
value = LuaToString(l, -1);
lua_pop(l, 1);
if (!strcmp(value, "caster")) {
location->Base = LocBaseCaster;
} else if (!strcmp(value, "target")) {
location->Base = LocBaseTarget;
} else {
LuaError(l, "Unsupported missile location base flag: %s" _C_ value);
}
} else if (!strcmp(value, "add-x")) {
lua_rawgeti(l, -1, j + 1);
location->AddX = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "add-y")) {
lua_rawgeti(l, -1, j + 1);
location->AddY = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "add-rand-x")) {
lua_rawgeti(l, -1, j + 1);
location->AddRandX = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "add-rand-y")) {
lua_rawgeti(l, -1, j + 1);
location->AddRandY = LuaToNumber(l, -1);
lua_pop(l, 1);
} else {
LuaError(l, "Unsupported missile location description flag: %s" _C_ value);
}
}
}
示例8: CclDefineRaceNames
/**
** Define race names
**
** @param l Lua state.
*/
static int CclDefineRaceNames(lua_State *l)
{
int i;
int j;
int k;
int args;
int subargs;
const char *value;
PlayerRaces.Count = 0;
args = lua_gettop(l);
for (j = 0; j < args; ++j) {
value = LuaToString(l, j + 1);
if (!strcmp(value, "race")) {
++j;
if (!lua_istable(l, j + 1)) {
LuaError(l, "incorrect argument");
}
subargs = luaL_getn(l, j + 1);
i = PlayerRaces.Count++;
PlayerRaces.Name[i] = NULL;
PlayerRaces.Display[i] = NULL;
PlayerRaces.Visible[i] = 0;
for (k = 0; k < subargs; ++k) {
lua_rawgeti(l, j + 1, k + 1);
value = LuaToString(l, -1);
lua_pop(l, 1);
if (!strcmp(value, "name")) {
++k;
lua_rawgeti(l, j + 1, k + 1);
PlayerRaces.Name[i] = new_strdup(LuaToString(l, -1));
lua_pop(l, 1);
} else if (!strcmp(value, "display")) {
++k;
lua_rawgeti(l, j + 1, k + 1);
PlayerRaces.Display[i] = new_strdup(LuaToString(l, -1));
lua_pop(l, 1);
} else if (!strcmp(value, "visible")) {
PlayerRaces.Visible[i] = 1;
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}
}
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}
}
return 0;
}
示例9: PUSH_ERROR_HANDLER
// Return number of accepted items to be taken
int ScriptApiDetached::detached_inventory_AllowTake(
const std::string &name,
const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
// Push callback function on stack
if (!getDetachedInventoryCallback(name, "allow_take"))
return stack.count; // All will be accepted
// Call function(inv, listname, index, stack, player)
InventoryLocation loc;
loc.setDetached(name);
InvRef::create(L, loc); // inv
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
if (!lua_isnumber(L, -1))
throw LuaError("allow_take should return a number. name=" + name);
int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler
return ret;
}
示例10: 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;
}
示例11: 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;
}
示例12: getServer
// Return number of accepted items to be put
int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
INodeDefManager *ndef = getServer()->ndef();
// If node doesn't exist, we don't know what callback to call
MapNode node = getEnv()->getMap().getNodeNoEx(p);
if (node.getContent() == CONTENT_IGNORE)
return 0;
// Push callback function on stack
std::string nodename = ndef->get(node).name;
if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_put"))
return stack.count;
// Call function(pos, listname, index, stack, player)
push_v3s16(L, p); // pos
lua_pushstring(L, listname.c_str()); // listname
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
if(!lua_isnumber(L, -1))
throw LuaError("allow_metadata_inventory_put should"
" return a number, guilty node: " + nodename);
int num = luaL_checkinteger(L, -1);
lua_pop(L, 1); // Pop integer
return num;
}
示例13: LuaError
/**
** Parse an animation
*/
static CAnimation *ParseAnimation(lua_State *l, int idx)
{
if (!lua_istable(l, idx)) {
LuaError(l, "incorrect argument");
}
const int args = lua_rawlen(l, idx);
if (args == 0) {
return NULL;
}
Labels.clear();
LabelsLater.clear();
const char *str = LuaToString(l, idx, 1);
CAnimation *firstAnim = ParseAnimationFrame(l, str);
CAnimation *prev = firstAnim;
for (int j = 1; j < args; ++j) {
const char *str = LuaToString(l, idx, j + 1);
CAnimation *anim = ParseAnimationFrame(l, str);
prev->Next = anim;
prev = anim;
}
prev->Next = firstAnim;
FixLabels(l);
return firstAnim;
}
示例14: checkobject
int LuaVoxelManip::l_set_lighting(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
if (!o->is_mapgen_vm)
return 0;
if (!lua_istable(L, 2))
return 0;
u8 light;
light = (getintfield_default(L, 2, "day", 0) & 0x0F);
light |= (getintfield_default(L, 2, "night", 0) & 0x0F) << 4;
MMVManip *vm = o->vm;
v3s16 yblock = v3s16(0, 1, 0) * MAP_BLOCKSIZE;
v3s16 pmin = lua_istable(L, 3) ? check_v3s16(L, 3) : vm->m_area.MinEdge + yblock;
v3s16 pmax = lua_istable(L, 4) ? check_v3s16(L, 4) : vm->m_area.MaxEdge - yblock;
sortBoxVerticies(pmin, pmax);
if (!vm->m_area.contains(VoxelArea(pmin, pmax)))
throw LuaError("Specified voxel area out of VoxelManipulator bounds");
Mapgen mg;
mg.vm = vm;
mg.setLighting(light, pmin, pmax);
return 0;
}
示例15: CclDefineBurningBuilding
/**
** Define burning building missiles.
**
** @param l Lua state.
*/
static int CclDefineBurningBuilding(lua_State *l)
{
for (std::vector<BurningBuildingFrame *>::iterator i = BurningBuildingFrames.begin();
i != BurningBuildingFrames.end(); ++i) {
delete *i;
}
BurningBuildingFrames.clear();
const int args = lua_gettop(l);
for (int j = 0; j < args; ++j) {
if (!lua_istable(l, j + 1)) {
LuaError(l, "incorrect argument");
}
BurningBuildingFrame *ptr = new BurningBuildingFrame;
const int subargs = lua_rawlen(l, j + 1);
for (int k = 0; k < subargs; ++k) {
const char *value = LuaToString(l, j + 1, k + 1);
++k;
if (!strcmp(value, "percent")) {
ptr->Percent = LuaToNumber(l, j + 1, k + 1);
} else if (!strcmp(value, "missile")) {
ptr->Missile = MissileTypeByIdent(LuaToString(l, j + 1, k + 1));
}
}
BurningBuildingFrames.insert(BurningBuildingFrames.begin(), ptr);
}
return 0;
}