当前位置: 首页>>代码示例>>C++>>正文


C++ script_error函数代码示例

本文整理汇总了C++中script_error函数的典型用法代码示例。如果您正苦于以下问题:C++ script_error函数的具体用法?C++ script_error怎么用?C++ script_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了script_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: evaluate_function

svalue_t evaluate_function(int start, int stop)
{
  svariable_t *func = NULL;
  int startpoint, endpoint;

  // the arguments need to be built locally in case of
  // function returns as function arguments eg
  // print("here is a random number: ", rnd() );
  
  int argc;
  svalue_t argv[MAXARGS];

  if (tokens[start].type != TO_function || tokens[stop].type != TO_oper || tokens[stop].v[0] != ')')
    script_error("misplaced closing bracket\n");
  // all the functions are stored in the global script
  else if (!(func = global_script.variableforname(tokens[start].v)))
    script_error("no such function: '%s'\n", tokens[start].v);
  else if (func->type != svt_function)
    script_error("'%s' not a function\n", tokens[start].v);

  if (killscript) return nullvar; // one of the above errors occurred

  // build the argument list
  // use a C command-line style system rather than
  // a system using a fixed length list

  argc = 0;
  endpoint = start + 2;   // ignore the function name and first bracket
  
  while (endpoint < stop)
    {
      startpoint = endpoint;
      endpoint = find_operator(startpoint, stop-1, ",");
      
      // check for -1: no more ','s 
      if (endpoint == -1)
	endpoint = stop; // evaluate the last expression

      if (endpoint-1 < startpoint)
	break;
      
      argv[argc] = evaluate_expression(startpoint, endpoint-1);
      endpoint++;    // skip the ','
      argc++;
    }

  // store the arguments in the global arglist
  t_argc = argc;
  t_argv = argv;

  if(killscript) return nullvar;
  
  // now run the function
  func->value.handler();
  
  // return the returned value
  return t_return;
}
开发者ID:meiavy,项目名称:doom-legacy,代码行数:58,代码来源:t_vari.cpp

示例2: script_error

void FParser::OPdecrement(svalue_t &result, int start, int n, int stop)
{
	if(start == n)          // ++n
    {
		DFsVariable *var;
		
		var = Script->FindVariable(Tokens[stop]);
		if(!var)
		{
			script_error("unknown variable '%s'\n", Tokens[stop]);
		}
		var->GetValue(result);
		
		// haleyjd
		if(var->type != svt_fixed)
		{
			result.value.i = intvalue(result) - 1;
			result.type = svt_int;
			var->SetValue (result);
		}
		else
		{
			result.setDouble(floatvalue(result)-1);
			result.type = svt_fixed;
			var->SetValue (result);
		}
    }
	else if(stop == n)   // n++
    {
		svalue_t newvalue;
		DFsVariable *var;
		
		var = Script->FindVariable(Tokens[start]);
		if(!var)
		{
			script_error("unknown variable '%s'\n", Tokens[start]);
		}
		var->GetValue(result);
		
		// haleyjd
		if(var->type != svt_fixed)
		{
			newvalue.type = svt_int;
			newvalue.value.i = intvalue(result) - 1;
			var->SetValue (newvalue);
		}
		else
		{
			newvalue.setDouble(floatvalue(result)-1);
			var->SetValue (newvalue);
		}
    }
	else
	{
		script_error("incorrect arguments to ++ operator\n");
	}
}
开发者ID:Accusedbold,项目名称:zdoom,代码行数:57,代码来源:t_oper.cpp

示例3: switch

void DFsVariable::SetValue(FLevelLocals *Level, const svalue_t &newvalue)
{
	if(type == svt_const)
    {
		// const adapts to the value it is set to
		type = newvalue.type;
    }

	switch (type)
	{
	case svt_int:
		value.i = intvalue(newvalue);
		break;

	case svt_string:
		if (newvalue.type == svt_string)
		{
			string = newvalue.string;
		}
		else
		{
			string = stringvalue(newvalue);
		}
		break;

	case svt_fixed:
		value.fixed = fixedvalue(newvalue);
		break;
	
	case svt_mobj:
		actor = actorvalue(Level, newvalue);
		break;
	
	case svt_pInt:
		*value.pI = intvalue(newvalue);
		break;
	
	case svt_pMobj:
		*value.pMobj = actorvalue(Level, newvalue);
		break;
	
	case svt_function:
		script_error("attempt to set function to a value\n");
		break;

	default:
		script_error("invalid variable type\n");
		break;
	}
}
开发者ID:coelckers,项目名称:gzdoom,代码行数:50,代码来源:t_variable.cpp

示例4: parse_include

void parse_include(char *lumpname)
{
  int lumpnum;
  char *lump, *end;
  char *saved_rover;
  
  if(-1 == (lumpnum = W_GetNumForName(lumpname)) )
    {
      script_error("include lump '%s' not found!\n", lumpname);
      return;
    }
  
  lump = W_CacheLumpNum(lumpnum, PU_STATIC);
  
  // realloc bigger for NULL at end
  lump = Z_Realloc(lump, W_LumpLength(lumpnum)+10, PU_STATIC, NULL);
  
  saved_rover = rover;    // save rover during include
  rover = lump; end = lump+W_LumpLength(lumpnum);
  *end = 0;
  
  // preprocess the include
  // we assume that it does not include sections or labels or 
  // other nasty things
  process_find_char(lump, 0);
  
  // now parse the lump
  parse_data(lump, end);
  
  // restore rover
  rover = saved_rover;
  
  // free the lump
  Z_Free(lump);
}
开发者ID:dorienh,项目名称:smmu,代码行数:35,代码来源:t_prepro.c

示例5: lua_getglobal

void AsyncEngine::step(lua_State *L, int errorhandler)
{
	lua_getglobal(L, "engine");
	resultQueueMutex.Lock();
	while (!resultQueue.empty()) {
		LuaJobInfo jobDone = resultQueue.front();
		resultQueue.pop_front();

		lua_getfield(L, -1, "async_event_handler");

		if (lua_isnil(L, -1)) {
			assert("Async event handler does not exist!" == 0);
		}

		luaL_checktype(L, -1, LUA_TFUNCTION);

		lua_pushinteger(L, jobDone.id);
		lua_pushlstring(L, jobDone.serializedResult.data(),
				jobDone.serializedResult.size());

		if (lua_pcall(L, 2, 0, errorhandler)) {
			script_error(L);
		}
	}
	resultQueueMutex.Unlock();
	lua_pop(L, 1); // Pop engine
}
开发者ID:Belugion,项目名称:minetest,代码行数:27,代码来源:s_async.cpp

示例6: assert

void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
		u32 active_object_count, u32 active_object_count_wider)
{
	GameScripting *scriptIface = env->getScriptIface();
	scriptIface->realityCheck();

	lua_State *L = scriptIface->getStack();
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	// Get minetest.registered_abms
	lua_getglobal(L, "minetest");
	lua_getfield(L, -1, "registered_abms");
	luaL_checktype(L, -1, LUA_TTABLE);
	int registered_abms = lua_gettop(L);

	// Get minetest.registered_abms[m_id]
	lua_pushnumber(L, m_id);
	lua_gettable(L, registered_abms);
	if(lua_isnil(L, -1))
		assert(0);

	// Call action
	luaL_checktype(L, -1, LUA_TTABLE);
	lua_getfield(L, -1, "action");
	luaL_checktype(L, -1, LUA_TFUNCTION);
	push_v3s16(L, p);
	pushnode(L, n, env->getGameDef()->ndef());
	lua_pushnumber(L, active_object_count);
	lua_pushnumber(L, active_object_count_wider);
	if(lua_pcall(L, 4, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
}
开发者ID:korovan,项目名称:minetest,代码行数:33,代码来源:l_env.cpp

示例7: lua_pushcfunction

void AsyncEngine::Step(lua_State *L) {
	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L);
	lua_getglobal(L, "engine");
	m_ResultQueueMutex.Lock();
	while(!m_ResultQueue.empty()) {
		LuaJobInfo jobdone = m_ResultQueue.front();
		m_ResultQueue.erase(m_ResultQueue.begin());

		lua_getfield(L, -1, "async_event_handler");

		if(lua_isnil(L, -1))
			assert("Someone managed to destroy a async callback in engine!" == 0);

		luaL_checktype(L, -1, LUA_TFUNCTION);

		lua_pushinteger(L, jobdone.JobId);
		lua_pushlstring(L, jobdone.serializedResult.c_str(),
				jobdone.serializedResult.length());

		if(lua_pcall(L, 2, 0, errorhandler)) {
			script_error(L);
		}
	}
	m_ResultQueueMutex.Unlock();
	lua_pop(L, 2); // Pop engine and error handler
}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:27,代码来源:l_async_events.cpp

示例8: log_deprecated

void log_deprecated(lua_State *L, std::string message)
{
	static bool configured = false;
	static bool dolog      = false;
	static bool doerror    = false;

	// performance optimization to not have to read and compare setting for every logline
	if (!configured) {
		std::string value = g_settings->get("deprecated_lua_api_handling");
		if (value == "log") {
			dolog = true;
		}
		if (value == "error") {
			dolog = true;
			doerror = true;
		}
	}

	if (doerror) {
		if (L != NULL) {
			script_error(L);
		} else {
			FATAL_ERROR("Can't do a scripterror for this deprecated message, so exit completely!");
		}
	}

	if (dolog) {
		/* abusing actionstream because of lack of file-only-logged loglevel */
		actionstream << message << std::endl;
		if (L != NULL) {
			actionstream << script_get_backtrace(L) << std::endl;
		}
	}
}
开发者ID:prodigeni,项目名称:freeminer,代码行数:34,代码来源:c_internal.cpp

示例9: script_cmd_make_op3sec

struct script_cmd* script_cmd_make_op3sec(const char* arg0, struct script_exp* arg1, struct script_cmd* arg2)
{
	if (strcmp(arg0, "while") == 0) {
		struct script_cmd* cmd = script_cmd_alloc();
		cmd->type = SCRIPT_CMD_WHILE;
		cmd->data.op2ec.arg0 = arg1;
		cmd->data.op2ec.arg1 = arg2;
		return cmd;
	} else if (strcmp(arg0, "repeat") == 0) {
		struct script_cmd* cmd = script_cmd_alloc();
		cmd->type = SCRIPT_CMD_REPEAT;
		cmd->data.op2ecd.arg0 = arg1;
		cmd->data.op2ecd.arg1 = arg2;
		cmd->data.op2ecd.value_set = 0;
		cmd->data.op2ecd.value = 0;
		return cmd;
	} else if (strcmp(arg0, "if") == 0) {
		struct script_cmd* cmd = script_cmd_alloc();
		cmd->type = SCRIPT_CMD_IF;
		cmd->data.op2ec.arg0 = arg1;
		cmd->data.op2ec.arg1 = arg2;
		return cmd;
	} else {
		char buffer[128];
		snprintf(buffer, sizeof(buffer), "Unknown command %s", arg0);
		script_error(buffer);
		return 0;
	}
}
开发者ID:amadvance,项目名称:advancemame,代码行数:29,代码来源:script.c

示例10: lua_getglobal

// minetest.get_objects_inside_radius(pos, radius)
int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
{
	// Get the table insert function
	lua_getglobal(L, "table");
	lua_getfield(L, -1, "insert");
	int table_insert = lua_gettop(L);

	GET_ENV_PTR;

	// Do it
	v3f pos = checkFloatPos(L, 1);
	float radius = luaL_checknumber(L, 2) * BS;
	std::set<u16> ids = env->getObjectsInsideRadius(pos, radius);
	lua_newtable(L);
	int table = lua_gettop(L);
	for(std::set<u16>::const_iterator
			i = ids.begin(); i != ids.end(); i++){
		ServerActiveObject *obj = env->getActiveObject(*i);
		// Insert object reference into table
		lua_pushvalue(L, table_insert);
		lua_pushvalue(L, table);
		getScriptApiBase(L)->objectrefGetOrCreate(obj);
		if(lua_pcall(L, 2, 0, 0))
			script_error(L, "error: %s", lua_tostring(L, -1));
	}
	return 1;
}
开发者ID:korovan,项目名称:minetest,代码行数:28,代码来源:l_env.cpp

示例11: script_run_callbacks

// Push the list of callbacks (a lua table).
// Then push nargs arguments.
// Then call this function, which
// - runs the callbacks
// - replaces the table and arguments with the return value,
//     computed depending on mode
void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode)
{
	assert(lua_gettop(L) >= nargs + 1);

	// Insert error handler
	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L) - nargs - 1;
	lua_insert(L, errorhandler);

	// Insert minetest.run_callbacks between error handler and table
	lua_getglobal(L, "minetest");
	lua_getfield(L, -1, "run_callbacks");
	lua_remove(L, -2);
	lua_insert(L, errorhandler + 1);

	// Insert mode after table
	lua_pushnumber(L, (int) mode);
	lua_insert(L, errorhandler + 3);

	// Stack now looks like this:
	// ... <error handler> <run_callbacks> <table> <mode> <arg#1> <arg#2> ... <arg#n>

	if (lua_pcall(L, nargs + 2, 1, errorhandler)) {
		script_error(L);
	}

	lua_remove(L, -2); // Remove error handler
}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:34,代码来源:c_internal.cpp

示例12: read_item

// minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
	GET_ENV_PTR;

	// pos
	//v3f pos = checkFloatPos(L, 1);
	// item
	ItemStack item = read_item(L, 2,getServer(L));
	if(item.empty() || !item.isKnown(getServer(L)->idef()))
		return 0;
	// Use minetest.spawn_item to spawn a __builtin:item
	lua_getglobal(L, "minetest");
	lua_getfield(L, -1, "spawn_item");
	if(lua_isnil(L, -1))
		return 0;
	lua_pushvalue(L, 1);
	lua_pushstring(L, item.getItemString().c_str());
	if(lua_pcall(L, 2, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	return 1;
	/*lua_pushvalue(L, 1);
	lua_pushstring(L, "__builtin:item");
	lua_pushstring(L, item.getItemString().c_str());
	return l_add_entity(L);*/
	/*// Do it
	ServerActiveObject *obj = createItemSAO(env, pos, item.getItemString());
	int objectid = env->addActiveObject(obj);
	// If failed to add, return nothing (reads as nil)
	if(objectid == 0)
		return 0;
	// Return ObjectRef
	objectrefGetOrCreate(L, obj);
	return 1;*/
}
开发者ID:korovan,项目名称:minetest,代码行数:36,代码来源:l_env.cpp

示例13: script_error

bool FParser::spec_if()
{
	int endtoken;
	svalue_t eval;
	
	
	if((endtoken = FindOperator(0, NumTokens-1, ")")) == -1)
    {
		script_error("parse error in if statement\n");
		return false;
    }
	
	// 2 to skip past the 'if' and '('
	EvaluateExpression(eval, 2, endtoken-1);
	bool ifresult = !!intvalue(eval);
	
	if(Section && BraceType == bracket_open && endtoken == NumTokens-1)
    {
		// {} braces
		if(!ifresult)       // skip to end of section
			Rover = Script->SectionEnd(Section) + 1;
    }
	else if(ifresult) // if() without {} braces
	{
		// nothing to do ?
		if(endtoken != NumTokens-1)
			EvaluateExpression(eval, endtoken+1, NumTokens-1);
	}
	
	return ifresult;
}
开发者ID:coelckers,项目名称:gzdoom,代码行数:31,代码来源:t_spec.cpp

示例14: scriptapi_item_on_place

bool scriptapi_item_on_place(lua_State *L, ItemStack &item,
		ServerActiveObject *placer, const PointedThing &pointed)
{
actionstream<<"DebugTracePlaceEnteredLua scriptapi_item Line 250 "<<std::endl;
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);
actionstream<<"DebugTracePlacePassedStackCheck scriptapi_item Line 254 "<<std::endl;
	// Push callback function on stack
	if(!get_item_callback(L, item.name.c_str(), "on_place"))
actionstream<<"DebugTracePlaceLuaReturningFalse scriptapi_item Line 257 "<<std::endl;
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectref_get_or_create(L, placer);
	push_pointed_thing(L, pointed);
actionstream<<"DebugTracePlaceClearToRunLua scriptapi_item Line 263 "<<std::endl;
	if(lua_pcall(L, 3, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	if(!lua_isnil(L, -1))
actionstream<<"DebugTracePlaceItemReturned scriptapi_item Line 267 "<<std::endl;
		item = read_item(L, -1);
actionstream<<"DebugTracePlaceLuaReturningTrue scriptapi_item Line 270 "<<std::endl;
	return true;
}
开发者ID:hexafraction,项目名称:minetest-debug-testing,代码行数:26,代码来源:scriptapi_item.cpp

示例15: read_item

// add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
	GET_ENV_PTR;

	// pos
	//v3f pos = checkFloatPos(L, 1);
	// item
	ItemStack item = read_item(L, 2,getServer(L));
	if(item.empty() || !item.isKnown(getServer(L)->idef()))
		return 0;

	lua_pushcfunction(L, script_error_handler);
	int errorhandler = lua_gettop(L);

	// Use spawn_item to spawn a __builtin:item
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "spawn_item");
	lua_remove(L, -2); // Remove core
	if(lua_isnil(L, -1))
		return 0;
	lua_pushvalue(L, 1);
	lua_pushstring(L, item.getItemString().c_str());
	if(lua_pcall(L, 2, 1, errorhandler))
		script_error(L);
	lua_remove(L, errorhandler); // Remove error handler
	return 1;
}
开发者ID:nsd2,项目名称:freeminer,代码行数:29,代码来源:l_env.cpp


注:本文中的script_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。