/* Set a string global's value by the name. */ void setglobals(avm* vm, const char* idname, const char* sval) { word w; float soff = newstring(vm, (char*)sval); sets(&w, soff); setglobal(vm, idname, &w); }
static void rec_chat(unsigned short channel,char *text) { int n; unsigned int bit; if (channel==0) { for (n=1; n<MAXCHARS; n++) { if (!ch[n].flags) continue; log_char(n,LOG_SYSTEM,0,"%s",text); } } else if (channel<1024) { int uID,cnr=0,step,anr=0,mnr=0; bit=1<<(channel-1); uID=atoi(text); if (channel==7 || channel==12 || channel==13) { cnr=atoi(text+11); step=14; } else if (channel==8) { anr=atoi(text+11); step=14; } else if (channel==9) { anr=atoi(text+11); mnr=atoi(text+14); step=17; } else step=10; for (n=1; n<MAXCHARS; n++) { if (!ch[n].flags) continue; if (!(ch[n].channel&bit)) continue; if (channel==31 && !(ch[n].flags&(CF_STAFF|CF_GOD))) { ch[n].channel&=~bit; continue; } if (channel==32 && !(ch[n].flags&CF_GOD)) { ch[n].channel&=~bit; continue; } if (ignoring(n,uID)) continue; if (channel==7 && cnr!=get_char_clan(n)) continue; if (channel==12 && cnr!=get_char_clan(n) && !clan_alliance(cnr,get_char_clan(n))) continue; if (anr && anr!=areaID) continue; if (mnr && mnr!=areaM) continue; if (channel==13 && get_char_club(n)!=cnr) continue; log_char(n,LOG_SYSTEM,0,"%s",text+step); } } else if (channel==1024 || channel==1030) { // tell int cnID,coID,ret; char buf[80]; cnID=atoi(text); coID=atoi(text+11); for (n=1; n<MAXCHARS; n++) { if (!ch[n].flags) continue; if (ch[n].ID!=cnID) continue; if (channel!=1030 && (ch[n].flags&CF_NOTELL)) continue; if (channel!=1030 && ignoring(n,coID)) continue; ret=log_char(n,LOG_SYSTEM,0,"°c6%s",text+22); if (ret && coID) { // server sends messages with ID 0 and does not need a received note sprintf(buf,"%010u:%010u",coID,cnID); server_chat(1029,buf); } } } else if (channel==1026) { // allow int cnID,coID; cnID=atoi(text); coID=atoi(text+11); allow_body_db(cnID,coID); } else if (channel==1027) { // look int cnID,coID; cnID=atoi(text); coID=atoi(text+11); look_values_bg(cnID,coID); } else if (channel==1028) { // dungeon-clan clan_dungeon_chat(text); } else if (channel==1029) { // chat receive ack int cnID,coID; cnID=atoi(text); coID=atoi(text+11); for (n=1; n<MAXCHARS; n++) { if (!ch[n].flags) continue; if (ch[n].ID!=cnID) continue; register_rec_tell(n,coID); } } else if (channel==1031) { // whostaff request int cnID; cnID=atoi(text); do_whostaff(cnID); } else if (channel==1032) { // look int cnID,coID; cnID=atoi(text); coID=atoi(text+11); lollipop_bg(cnID,coID); } else if (channel==1033) { // shutdown int t,m; t=atoi(text); m=atoi(text+11); shutdown_bg(t,m); } else if (channel==1034) { // shutup int cnID,coID,minutes; void shutup_bg(int,int,int); cnID=atoi(text); coID=atoi(text+11); minutes=atoi(text+22); shutup_bg(cnID,coID,minutes); } else if (channel==1035) { // setglobal int idx,value; idx=atoi(text); value=atoi(text+11); setglobal(idx,value); } else if (channel==1036) { // destroy items in body int cnID,IID; cnID=atoi(text); IID=atoi(text+11); remove_item_from_body_bg(cnID,IID); } }
void lua_setglobal (char *name) { checkCparams(1); setglobal(luaI_findsymbolbyname(name)); }
/* ** Execute the given opcode, until a RET. Parameters are between ** [stack+base,top). Returns n such that the the results are between ** [stack+n,top). */ static StkId lua_execute (Byte *pc, StkId base) { if (lua_callhook) callHook (base, LUA_T_MARK, 0); while (1) { OpCode opcode; switch (opcode = (OpCode)*pc++) { case PUSHNIL: ttype(top) = LUA_T_NIL; incr_top; break; case PUSH0: case PUSH1: case PUSH2: ttype(top) = LUA_T_NUMBER; nvalue(top) = opcode-PUSH0; incr_top; break; case PUSHBYTE: ttype(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; break; case PUSHWORD: { Word w; get_word(w,pc); ttype(top) = LUA_T_NUMBER; nvalue(top) = w; incr_top; } break; case PUSHFLOAT: { real num; get_float(num,pc); ttype(top) = LUA_T_NUMBER; nvalue(top) = num; incr_top; } break; case PUSHSTRING: { Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; } break; case PUSHFUNCTION: { TFunc *f; get_code(f,pc); luaI_insertfunction(f); /* may take part in GC */ top->ttype = LUA_T_FUNCTION; top->value.tf = f; incr_top; } break; case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: case PUSHLOCAL9: *top = *((stack+base) + (int)(opcode-PUSHLOCAL0)); incr_top; break; case PUSHLOCAL: *top = *((stack+base) + (*pc++)); incr_top; break; case PUSHGLOBAL: { Word w; get_word(w,pc); getglobal(w); } break; case PUSHINDEXED: pushsubscript(); break; case PUSHSELF: { TObject receiver = *(top-1); Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; pushsubscript(); *top = receiver; incr_top; break; } case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: case STORELOCAL8: case STORELOCAL9: *((stack+base) + (int)(opcode-STORELOCAL0)) = *(--top); break; case STORELOCAL: *((stack+base) + (*pc++)) = *(--top); break; case STOREGLOBAL: { Word w; get_word(w,pc); setglobal(w); } break; case STOREINDEXED0: storesubscript(top-3, 1); break; case STOREINDEXED: { int n = *pc++; storesubscript(top-3-n, 2); break; } case STORELIST0: case STORELIST: { int m, n; TObject *arr; if (opcode == STORELIST0) m = 0; else m = *(pc++) * FIELDS_PER_FLUSH; n = *(pc++); arr = top-n-1; while (n) { ttype(top) = LUA_T_NUMBER; nvalue(top) = n+m; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } break; case STORERECORD: /* opcode obsolete: supersed by STOREMAP */ { int n = *(pc++); TObject *arr = top-n-1; while (n) { Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } break; case STOREMAP: { int n = *(pc++); TObject *arr = top-(2*n)-1; while (n--) { *(lua_hashdefine (avalue(arr), top-2)) = *(top-1); top-=2; } } break; case ADJUST0: adjust_top(base); break; case ADJUST: { StkId newtop = base + *(pc++); adjust_top(newtop); break; } case VARARGS: adjust_varargs(base + *(pc++)); break; case CREATEARRAY: { Word size; get_word(size,pc); avalue(top) = lua_createarray(size); ttype(top) = LUA_T_ARRAY; incr_top; } break; case EQOP: { int res = lua_equalObj(top-2, top-1); --top; ttype(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; } break; case LTOP: comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); break; case LEOP: comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); break; case GTOP: comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); break; case GEOP: comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); break; case ADDOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_ADD); else { nvalue(l) += nvalue(r); --top; } } break; case SUBOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_SUB); else { nvalue(l) -= nvalue(r); --top; } } break; case MULTOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_MUL); else { nvalue(l) *= nvalue(r); --top; } } break; case DIVOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_DIV); else { nvalue(l) /= nvalue(r); --top; } } break; case POWOP: call_arith(IM_POW); break; case CONCOP: { TObject *l = top-2; TObject *r = top-1; if (tostring(l) || tostring(r)) call_binTM(IM_CONCAT, "unexpected type for concatenation"); else { tsvalue(l) = lua_createstring(lua_strconc(svalue(l),svalue(r))); --top; } } break; case MINUSOP: if (tonumber(top-1)) { ttype(top) = LUA_T_NIL; incr_top; call_arith(IM_UNM); } else nvalue(top-1) = - nvalue(top-1); break; case NOTOP: ttype(top-1) = (ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; break; case ONTJMP: { Word w; get_word(w,pc); if (ttype(top-1) != LUA_T_NIL) pc += w; } break; case ONFJMP: { Word w; get_word(w,pc); if (ttype(top-1) == LUA_T_NIL) pc += w; } break; case JMP: { Word w; get_word(w,pc); pc += w; } break; case UPJMP: { Word w; get_word(w,pc); pc -= w; } break; case IFFJMP: { Word w; get_word(w,pc); top--; if (ttype(top) == LUA_T_NIL) pc += w; } break; case IFFUPJMP: { Word w; get_word(w,pc); top--; if (ttype(top) == LUA_T_NIL) pc -= w; } break; case POP: --top; break; case CALLFUNC: { int nParams = *(pc++); int nResults = *(pc++); StkId newBase = (top-stack)-nParams; do_call(newBase, nResults); } break; case RETCODE0: case RETCODE: if (lua_callhook) callHook (base, LUA_T_MARK, 1); return (base + ((opcode==RETCODE0) ? 0 : *pc)); case SETLINE: { Word line; get_word(line,pc); if ((stack+base-1)->ttype != LUA_T_LINE) { /* open space for LINE value */ open_stack((top-stack)-base); base++; (stack+base-1)->ttype = LUA_T_LINE; } (stack+base-1)->value.i = line; if (lua_linehook) lineHook (line); break; } default: lua_error ("internal error - opcode doesn't match"); } } }
/* Set a float global's value by the name. */ void setglobalf(avm* vm, const char* idname, float fval) { word w; setf(&w, fval); setglobal(vm, idname, &w); }
/* Set an integer global's value by the name. */ void setglobali(avm* vm, const char* idname, int ival) { word w; seti(&w, ival); setglobal(vm, idname, &w); }