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; }
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"); } }
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; } }
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); }
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 }
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)); }
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 }
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; } } }
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; } }
// 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; }
// rollback_revert_actions_by(actor, seconds) -> bool, log messages int ModApiBasic::l_rollback_revert_actions_by(lua_State *L) { std::string actor = luaL_checkstring(L, 1); int seconds = luaL_checknumber(L, 2); Server *server = getServer(L); IRollbackManager *rollback = server->getRollbackManager(); std::list<RollbackAction> actions = rollback->getRevertActions(actor, seconds); std::list<std::string> log; bool success = server->rollbackRevertActions(actions, &log); // Push boolean result lua_pushboolean(L, success); // Get the table insert function and push the log table lua_getglobal(L, "table"); lua_getfield(L, -1, "insert"); int table_insert = lua_gettop(L); lua_newtable(L); int table = lua_gettop(L); for(std::list<std::string>::const_iterator i = log.begin(); i != log.end(); i++) { lua_pushvalue(L, table_insert); lua_pushvalue(L, table); lua_pushstring(L, i->c_str()); if(lua_pcall(L, 2, 0, 0)) script_error(L, "error: %s", lua_tostring(L, -1)); } lua_remove(L, -2); // Remove table lua_remove(L, -2); // Remove insert return 2; }
// 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 }
// 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;*/ }
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; }
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; }
// 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; }
struct script_cmd* script_cmd_make_op2se(const char* arg0, struct script_exp* arg1) { if (strcmp(arg0, "wait") == 0) { struct script_cmd* cmd = script_cmd_alloc(); cmd->type = SCRIPT_CMD_WAIT; cmd->data.op1e.arg0 = arg1; return cmd; } else if (strcmp(arg0, "delay") == 0) { struct script_cmd* cmd = script_cmd_alloc(); cmd->type = SCRIPT_CMD_DELAY; cmd->data.op1ed.arg0 = arg1; cmd->data.op1ed.value_set = 0; cmd->data.op1ed.value = 0; return cmd; } else if (strcmp(arg0, "evaluate") == 0) { struct script_cmd* cmd = script_cmd_alloc(); cmd->type = SCRIPT_CMD_EVALUATE; cmd->data.op1e.arg0 = arg1; return cmd; } else { char buffer[128]; snprintf(buffer, sizeof(buffer), "Unknown operation %s", arg0); script_error(buffer); return 0; } }
void FParser::spec_for() { svalue_t eval; int start; int comma1, comma2; // token numbers of the seperating commas if(!Section) { script_error("need {} delimiters for for()\n"); return; } // is a valid section start = 2; // skip "for" and "(": start on third token(2) // find the seperating commas first if( (comma1 = FindOperator(start, NumTokens-1, ",")) == -1 || (comma2 = FindOperator(comma1+1, NumTokens-1, ",")) == -1) { script_error("incorrect arguments to for()\n"); // haleyjd: return; // said if() } // are we looping back from a previous loop? if(Section == PrevSection) { // do the loop 'action' (third argument) EvaluateExpression(eval, comma2+1, NumTokens-2); // check if we should run the loop again (second argument) EvaluateExpression(eval, comma1+1, comma2-1); if(!intvalue(eval)) { // stop looping Rover = Script->SectionEnd(Section) + 1; } } else { // first time: starting the loop // just evaluate the starting expression (first arg) EvaluateExpression(eval, start, comma1-1); } }
int script_file_exec(const char *file) { int err = 0, handler; if ((err = luaL_loadfile(L, file)) != 0) { return script_error(L); } handler = lua_gettop(L); lua_pushcfunction(L, script_traceback); lua_insert(L, handler); err = lua_pcall(L, 0, LUA_MULTRET, handler); lua_remove(L, handler); if (err) { return script_error(L); } return SCRIPT_RC_OK; }
void setvariablevalue(svariable_t *v, svalue_t newvalue) { if(killscript) return; // protect the variables when killing script if(!v) return; if(v->type == svt_const) { // const adapts to the value it is set to v->type = newvalue.type; // alloc memory for string if(v->type == svt_string) // static incase a global_script var v->value.s = Z_Malloc(128, PU_STATIC, 0); } if(v->type == svt_int) v->value.i = intvalue(newvalue); if(v->type == svt_string) strcpy(v->value.s, stringvalue(newvalue)); if(v->type == svt_fixed) v->value.fixed = fixedvalue(newvalue); if(v->type == svt_mobj) v->value.mobj = MobjForSvalue(newvalue); if(v->type == svt_pInt) *v->value.pI = intvalue(newvalue); if(v->type == svt_pString) { // free old value free(*v->value.pS); // dup new string *v->value.pS = strdup(stringvalue(newvalue)); } if(v->type == svt_pFixed) *v->value.pFixed = fixedvalue(newvalue); if(v->type == svt_pMobj) *v->value.pMobj = MobjForSvalue(newvalue); if(v->type == svt_function) script_error("attempt to set function to a value\n"); }
void FParser::EvaluateExpression(svalue_t &result, int start, int stop) { int i, n; // possible pointless brackets if(TokenType[start] == operator_ && TokenType[stop] == operator_) PointlessBrackets(&start, &stop); if(start == stop) // only 1 thing to evaluate { SimpleEvaluate(result, start); return; } // go through each operator in order of precedence for(i=0; i<num_operators; i++) { // check backwards for the token. it has to be // done backwards for left-to-right reading: eg so // 5-3-2 is (5-3)-2 not 5-(3-2) if (operators[i].direction==forward) { n = FindOperatorBackwards(start, stop, operators[i].string); } else { n = FindOperator(start, stop, operators[i].string); } if( n != -1) { // call the operator function and evaluate this chunk of tokens (this->*operators[i].handler)(result, start, n, stop); return; } } if(TokenType[start] == function) { EvaluateFunction(result, start, stop); return; } // error ? { FString tempstr; for(i=start; i<=stop; i++) tempstr << Tokens[i] << ' '; script_error("couldnt evaluate expression: %s\n",tempstr.GetChars()); } }
// get_modnames() // the returned list is sorted alphabetically for you int ModApiBasic::l_get_modnames(lua_State *L) { NO_MAP_LOCK_REQUIRED; // Get a list of mods std::list<std::string> mods_unsorted, mods_sorted; getServer(L)->getModNames(mods_unsorted); // Take unsorted items from mods_unsorted and sort them into // mods_sorted; not great performance but the number of mods on a // server will likely be small. for(std::list<std::string>::iterator i = mods_unsorted.begin(); i != mods_unsorted.end(); ++i) { bool added = false; for(std::list<std::string>::iterator x = mods_sorted.begin(); x != mods_sorted.end(); ++x) { // I doubt anybody using Minetest will be using // anything not ASCII based :) if((*i).compare(*x) <= 0) { mods_sorted.insert(x, *i); added = true; break; } } if(!added) mods_sorted.push_back(*i); } // Get the table insertion function from Lua. lua_getglobal(L, "table"); lua_getfield(L, -1, "insert"); int insertion_func = lua_gettop(L); // Package them up for Lua lua_newtable(L); int new_table = lua_gettop(L); std::list<std::string>::iterator i = mods_sorted.begin(); while(i != mods_sorted.end()) { lua_pushvalue(L, insertion_func); lua_pushvalue(L, new_table); lua_pushstring(L, (*i).c_str()); if(lua_pcall(L, 2, 0, 0) != 0) { script_error(L, "error: %s", lua_tostring(L, -1)); } ++i; } return 1; }
void FParser::spec_while() { int endtoken; svalue_t eval; if(!Section) { script_error("no {} section given for loop\n"); return; } if( (endtoken = FindOperator(0, NumTokens-1, ")")) == -1) { script_error("parse error in loop statement\n"); return; } EvaluateExpression(eval, 2, endtoken-1); // skip if no longer valid if(!intvalue(eval)) Rover = Script->SectionEnd(Section) + 1; }
struct script_exp* script_exp_make_op1s(int type, const char* arg0) { struct script_exp* exp = script_exp_alloc(); exp->type = type; exp->data.op1s.eval = script_symbol_check(arg0, &exp->data.op1s.argextra); if (!exp->data.op1s.eval) { char buffer[128]; script_exp_free(exp); snprintf(buffer, sizeof(buffer), "Unknown symbol %s", arg0); script_error(buffer); return 0; } return exp; }
int script_str_exec(const char *cmd) { int err = 0, handler = 0; if ((err = luaL_loadstring(L, cmd)) != 0) { return script_error(L); } handler = lua_gettop(L); lua_pushcfunction(L, script_traceback); lua_insert(L, handler); err = lua_pcall(L, 0, LUA_MULTRET, handler); lua_remove(L, handler); if (err) { return script_error(L); } if (strstr(cmd, "res_code = ") != NULL) { lua_getglobal(L, "res_code"); if (lua_isnumber(L, -1)) { return lua_tointeger(L, -1); } } return SCRIPT_RC_OK; }
svalue_t evaluate_expression(int start, int stop) { int i, n; if(killscript) return nullvar; // killing the script // possible pointless brackets if(tokentype[start] == operator_ && tokentype[stop] == operator_) pointless_brackets(&start, &stop); if(start == stop) // only 1 thing to evaluate { return simple_evaluate(start); } // go through each operator in order of precedence for(i=0; i<num_operators; i++) { // check backwards for the token. it has to be // done backwards for left-to-right reading: eg so // 5-3-2 is (5-3)-2 not 5-(3-2) if( -1 != (n = (operators[i].direction==forward ? find_operator_backwards : find_operator) (start, stop, operators[i].string)) ) { // C_Printf("operator %s, %i-%i-%i\n", operators[count].string, start, n, stop); // call the operator function and evaluate this chunk of tokens return operators[i].handler(start, n, stop); } } if(tokentype[start] == function) return evaluate_function(start, stop); // error ? { char tempstr[1024]=""; for(i=start; i<=stop; i++) sprintf(tempstr,"%s %s", tempstr, tokens[i]); script_error("couldnt evaluate expression: %s\n",tempstr); return nullvar; } }
struct script_exp* script_exp_make_op2fe(int type, const char* arg0, struct script_exp* arg1) { struct script_exp* exp = script_exp_alloc(); exp->type = type; exp->data.op2fe.arg1 = arg1; exp->data.op2fe.eval = script_function2_check(arg0, &exp->data.op2fe.argextra); if (!exp->data.op2fe.eval) { char buffer[128]; script_exp_free(exp); snprintf(buffer, sizeof(buffer), "Unknown function %s", arg0); script_error(buffer); return 0; } return exp; }
void FParser::OPremainder(svalue_t &result, int start, int n, int stop) { svalue_t left, right; int ir; evaluate_leftnright(start, n, stop); if(!(ir = intvalue(right))) script_error("divide by zero\n"); else { result.type = svt_int; result.value.i = intvalue(left) % ir; } }
void scriptapi_create_auth(lua_State *L, const std::string &playername, const std::string &password) { realitycheck(L); assert(lua_checkstack(L, 20)); StackUnroller stack_unroller(L); get_auth_handler(L); lua_getfield(L, -1, "create_auth"); if(lua_type(L, -1) != LUA_TFUNCTION) throw LuaError(L, "Authentication handler missing create_auth"); lua_pushstring(L, playername.c_str()); lua_pushstring(L, password.c_str()); if(lua_pcall(L, 2, 0, 0)) script_error(L, "error: %s", lua_tostring(L, -1)); }
void FParser::OPequals(svalue_t &result, int start, int n, int stop) { DFsVariable *var; var = Script->FindVariable(Tokens[start]); if(var) { EvaluateExpression(result, n+1, stop); var->SetValue (result); } else { script_error("unknown variable '%s'\n", Tokens[start]); } }