// // SOUND frq, dur [, vol] [BG] // void cmd_sound() { int frq, ms = 250, vol = 100; int bg = 0; frq = par_getint(); if (!prog_error) { par_getcomma(); if (!prog_error) { ms = par_getint(); if (!prog_error) { if (code_peek() == kwTYPE_SEP) { par_getcomma(); if (!prog_error) { vol = par_getint(); } } if (code_peek() == kwBACKG) { code_skipnext(); bg = 1; } if (!prog_error) { dev_sound(frq, ms, vol, bg); } } } } }
// assign error to variable or match with next expression int err_throw_catch(const char *err) { var_t *arg; var_t v_catch; int caught = 1; switch (code_peek()) { case kwTYPE_VAR: arg = code_getvarptr(); v_setstr(arg, err); break; case kwTYPE_STR: v_init(&v_catch); eval(&v_catch); // catch is conditional on matching error caught = (v_catch.type == V_STR && strstr(err, v_catch.v.p.ptr) != NULL); v_free(&v_catch); break; case kwTYPE_EOC: case kwTYPE_LINE: break; default: rt_raise(ERR_INVALID_CATCH); break; } return caught; }
// throw user error void cmd_throw() { if (!gsb_last_error) { var_t v_throw; v_init(&v_throw); const char *err = ""; byte code = code_peek(); if (code != kwTYPE_EOC && code != kwTYPE_LINE) { eval(&v_throw); if (v_throw.type == V_STR) { err = v_throw.v.p.ptr; } } err_throw_str(err); v_free(&v_throw); } }
/** * build parameter table */ int slib_build_ptable(slib_par_t *ptable) { #if defined(LNX_EXTLIB) || defined(WIN_EXTLIB) int pcount = 0; var_t *arg = NULL; byte ready, code; bcip_t ofs; if (code_peek() == kwTYPE_LEVEL_BEGIN) { code_skipnext(); ready = 0; do { code = code_peek(); switch (code) { case kwTYPE_EOC: code_skipnext(); break; case kwTYPE_SEP: code_skipsep(); break; case kwTYPE_LEVEL_END: ready = 1; break; case kwTYPE_VAR: // variable ofs = prog_ip; if (code_isvar()) { // push parameter ptable[pcount].var_p = code_getvarptr(); ptable[pcount].byref = 1; pcount++; break; } // restore IP prog_ip = ofs; // no 'break' here default: // default --- expression (BYVAL ONLY) arg = v_new(); eval(arg); if (!prog_error) { // push parameter ptable[pcount].var_p = arg; ptable[pcount].byref = 0; pcount++; } else { v_free(arg); v_detach(arg); return pcount; } } } while (!ready); // kwTYPE_LEVEL_END code_skipnext(); } return pcount; #else return 0; #endif }