void exec_sle(){ char* s1; char* s2; s1 = pop_string(); s2 = pop_string(); push_bool(strcmp(s2,s1)<=0); }
void exec_neq(){ Odescr *e1 = pop_tstack(); Odescr *e2 = pop_tstack(); push_bool(odescr_equal(e1,e2)!=0); free_odescr(e1); free_odescr(e2); }
void LuaCreature::OnReachWP(uint32 iWaypointId, bool bForwards) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_REACH_WP]); push_creature(_unit); push_int(CREATURE_EVENT_ON_REACH_WP); push_int(iWaypointId); push_bool(bForwards); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
void input_schema(Pschema s, char *attr_name, int spaces, int pretty, FILE *in_file){ // reads a schema and puts it on the top op tstack if(attr_name!=NULL && pretty){ print_spaces(spaces, stdout); fprintf(stdout, "Input record attribute \"%s\"\n",attr_name); } if(pretty){ print_spaces(spaces, stdout); } if(s->type == TY_RECORD || s->type == TY_ARRAY || s->type == TY_ATTR){ int size = get_schema_size(s); int nfields = 0; switch(s->type){ case TY_RECORD:{ if(pretty){ fprintf(stdout,"Input for a record\n"); } Pschema temp = s->child; while(temp){ input_schema(temp->child, temp->id, spaces+1, pretty, in_file); nfields++; temp = temp->brother; } break; } case TY_ARRAY:{ int i; if(pretty){ fprintf(stdout, "Input for an array\n"); } nfields = s->size; for(i=0; i<nfields; i++){ input_schema(s->child, NULL, spaces+1, pretty, in_file); } break; } default: print_schema(s,0); machine_error("TY_ATTR cannot be used in input_schema()."); break; } exec_cat(nfields,size); } else{ switch(s->type){ case TY_INT: { int in = read_int(stdout, in_file, "Insert an integer: ", pretty); push_int(in); break; } case TY_CHAR: { char in = read_char(stdout, in_file, "Insert a char: ", pretty); push_char(in); break; } case TY_REAL: { float in = read_real(stdout, in_file, "Insert a number of type real: ", pretty); push_real(in); break; } case TY_STRING: { char *in = read_string(stdout, in_file, "Insert a string: ", pretty); char *strig_to_store = stringtable_store(in, stringtable); freemem(in, strlen(in) + 1); push_string(strig_to_store); break; } case TY_BOOL: { char in = read_char(stdout, in_file, "Insert a boolean (0 or 1): ", pretty); push_bool(in == '1'); break; } default: {machine_error("Unknown type of schema in input_schema()."); break;} } } }
bool run(struct context *context, struct byte_array *program, struct map *env, bool in_context) { null_check(context); null_check(program); program = byte_array_copy(program); program->current = program->data; struct program_state *state = NULL; enum Opcode inst = VM_NIL; if (context->runtime) { if (in_context) { if (!state) state = (struct program_state*)stack_peek(context->program_stack, 0); env = state->named_variables; // use the caller's variable set in the new state } else state = program_state_new(context, env); } while (program->current < program->data + program->length) { inst = (enum Opcode)*program->current; bool really = inst & VM_RLY; inst &= ~VM_RLY; #ifdef DEBUG display_program_counter(context, program); #endif program->current++; // increment past the instruction int32_t pc_offset = 0; switch (inst) { case VM_COM: case VM_ITR: if (iterate(context, inst, state, program)) goto done; break; case VM_RET: if (ret(context, program)) goto done; break; case VM_TRO: if (tro(context)) goto done; break; case VM_TRY: if (vm_trycatch(context, program)) goto done; break; case VM_EQU: case VM_MUL: case VM_DIV: case VM_ADD: case VM_SUB: case VM_NEQ: case VM_GTN: case VM_LTN: case VM_GRQ: case VM_LEQ: case VM_BND: case VM_BOR: case VM_MOD: case VM_XOR: case VM_INV: case VM_RSF: case VM_LSF: binary_op(context, inst); break; case VM_ORR: case VM_AND: pc_offset = boolean_op(context, program, inst); break; case VM_NEG: case VM_NOT: unary_op(context, inst); break; case VM_SRC: src(context, inst, program); break; case VM_DST: dst(context, really); break; case VM_STX: case VM_SET: set(context, inst, state, program); break; case VM_JMP: pc_offset = jump(context, program); break; case VM_IFF: pc_offset = iff(context, program); break; case VM_CAL: func_call(context, inst, program, NULL); break; case VM_LST: push_list(context, program); break; case VM_MAP: push_map(context, program); break; case VM_NIL: push_nil(context); break; case VM_INT: push_int(context, program); break; case VM_FLT: push_float(context, program); break; case VM_BUL: push_bool(context, program); break; case VM_STR: push_str(context, program); break; case VM_VAR: push_var(context, program); break; case VM_FNC: push_fnc(context, program); break; case VM_GET: list_get(context, really); break; case VM_PTX: case VM_PUT: list_put(context, inst, really); break; case VM_MET: method(context, program, really); break; default: vm_exit_message(context, ERROR_OPCODE); return false; } program->current += pc_offset; } if (!context->runtime) return false; done: if (!in_context) stack_pop(context->program_stack); return inst == VM_RET; }
/// copy a file. // @param src source file // @param dest destination file // @param fail_if_exists if true, then cannot copy onto existing file // @function copy_file def copy_file(Str src, Str dest, Int fail_if_exists = 0) { return push_bool(L, CopyFile(src,dest,fail_if_exists)); }
void exec_neg(){ push_bool(!pop_bool()); }
void exec_rgt(){ float n, m; n = pop_real(); m = pop_real(); push_bool(m>n); }
void exec_rle(){ float n, m; n = pop_real(); m = pop_real(); push_bool(m<=n); }
void exec_ige(){ int n, m; n = pop_int(); m = pop_int(); push_bool(m>=n); }
void exec_ile(){ int n, m; n = pop_int(); m = pop_int(); push_bool(m<=n); }
/// set a thread's priority // @param p positive integer to increase thread priority // @function set_priority def set_priority(Int p) { return push_bool(L, SetThreadPriority(this->thread,p)); }
/// make a beep sound. // @param type (default 'ok'); one of 'information','question','warning','error' // @function beep def beep (Str icon = "ok") { return push_bool(L, MessageBeep(mb_const(icon))); }
/// kill this thread. Generally considered a 'nuclear' option, but // this implementation will free any associated callback references, buffers // and handles. @{test-timer.lua} shows how a timer can be terminated. // @function kill def kill() { lcb_free(this->lcb); return push_bool(L, TerminateThread(this->thread,1)); }
/// resume a suspended thread. // @function resume def resume() { return push_bool(L, ResumeThread(this->thread) >= 0); }
/// suspend this thread. // @function suspend def suspend() { return push_bool(L, SuspendThread(this->thread) >= 0); }
/// execute a shell command. // @param verb the action (e.g. 'open' or 'edit') can be nil. // @param file the command // @param parms any parameters (optional) // @param dir the working directory (optional) // @param show the window show flags (default is SW_SHOWNORMAL) // @function shell_exec def shell_exec(StrNil verb, Str file, StrNil parms, StrNil dir, Int show=SW_SHOWNORMAL) { WCHAR wverb[128], wfile[MAX_WPATH], wdir[MAX_WPATH], wparms[MAX_WPATH]; int res = (DWORD_PTR)ShellExecuteW(NULL,wconv(verb),wconv(file),wconv(parms),wconv(dir),show) > 32; return push_bool(L, res); }
/// move a file. // @param src source file // @param dest destination file // @function move_file def move_file(Str src, Str dest) { return push_bool(L, MoveFile(src,dest)); }