void load_ply_info_cb(struct db_result *result) { //数据导入后的回调函数 if(result){ player_t ply = result->ud; if(result->result_set){ redisReply *r = (redisReply*)result->result_set; if(r->type != REDIS_REPLY_NIL){ lua_State *L = tls_get(LUASTATE); if(0 != CALL_LUA_FUNC2(L,"CreateLuaPlayer",1, PUSH_LUSRDATA(L,ply), PUSH_TABLE3(L, PUSH_STRING(L,r->element[0]->str), PUSH_STRING(L,r->element[1]->str), PUSH_STRING(L,r->element[2]->str)))) { const char * error = lua_tostring(L, -1); lua_pop(L,1); printf("%s\n",error); }else ply->_luaply = create_luaObj(L,-1); }else{ //没有角色,通知客户端创建角色 shortmsg2gate(CMD_GAME2C_CREATE,ply->_agentsession); } }else{ //数据库访问出错 shortmsg2gate(CMD_GAME2GATE_BUSY,ply->_agentsession); remove_player(ply); } } }
int main(int argc,char **argv) { lua_State *L = luaL_newstate(); luaL_openlibs(L); if (luaL_dofile(L,"node_echo.lua")) { const char * error = lua_tostring(L, -1); lua_pop(L,1); printf("%s\n",error); } CALL_LUA_FUNC1(L,"main",0, PUSH_TABLE2(L,PUSH_STRING(L,argv[1]), PUSH_NUMBER(L,atoi(argv[2]))) ); printf("end here\n"); return 0; }
bool CScriptCmd::Call(const std::string& szName) { //Call the script function size_t uiId = this->Find(szName); if (uiId != std::string::npos) { BEGIN_PARAMS(vArgs); PUSH_STRING(this->m_vCmds[uiId].szName); this->m_pScriptInt->CallScriptFunction(this->m_vCmds[uiId].pFunction, &vArgs, NULL); END_PARAMS(vArgs); return true; } return false; }
static int compare(char* pred, char* args, int match) { register int c; char* pptoken; long state; regex_t re; char tmp[MAXTOKEN + 1]; state = (pp.state & ~DISABLE); PUSH_STRING(args); pp.state |= PASSEOF; pptoken = pp.token; pp.token = tmp; if (!pplex()) goto bad; pp.token = pptoken; if (pplex() != ',' || !pplex()) goto bad; if (!match) c = strcmp(tmp, pp.token); else if ((c = regcomp(&re, pp.token, REG_AUGMENTED|REG_LENIENT|REG_NULL)) || (c = regexec(&re, tmp, NiL, 0, 0)) && c != REG_NOMATCH) regfatal(&re, 4, c); else { c = !c; regfree(&re); } if ((pp.state & PASSEOF) && pplex()) goto bad; pp.state = state; return c; bad: pp.token = pptoken; error(2, "%s: 2 arguments expected", pred); while (pplex()); pp.state = state; return 0; }
void ppbuiltin(void) { register int c; register char* p; register char* a; int n; int op; char* token; char* t; long number; long onumber; struct ppinstk* in; struct pplist* list; struct ppsymbol* sym; Sfio_t* sp; number = pp.state; pp.state |= DISABLE|FILEPOP|NOSPACE; token = pp.token; p = pp.token = pp.tmpbuf; *(a = pp.args) = 0; if ((c = pplex()) != T_ID) { error(2, "%s: #(<identifier>...) expected", p); *p = 0; } switch (op = (int)hashget(pp.strtab, p)) { case V_DEFAULT: n = 0; p = pp.token = pp.valbuf; if ((c = pplex()) == ',') { op = -1; c = pplex(); } pp.state &= ~NOSPACE; for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; else if (c == ',' && !n && op > 0) op = 0; if (op) pp.token = pp.toknxt; c = pplex(); } *pp.token = 0; pp.token = token; pp.state = number; break; case V_EMPTY: p = pp.valbuf; if ((c = pplex()) == ')') *p = '1'; else { *p = '0'; n = 0; for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; c = pplex(); } } *(p + 1) = 0; pp.token = token; pp.state = number; break; case V_ITERATE: n = 0; pp.token = pp.valbuf; if ((c = pplex()) != T_ID || !(sym = ppsymref(pp.symtab, pp.token)) || !sym->macro || sym->macro->arity != 1 || (c = pplex()) != ',') { error(2, "#(%s <macro(x)>, ...) expected", p); for (;;) { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if (c == '(') n++; else if (c == ')' && !n--) break; c = pplex(); } *pp.valbuf = 0; } else while (c != ')') { p = pp.token; if (pp.token > pp.valbuf) *pp.token++ = ' '; STRCOPY(pp.token, sym->name, a); *pp.token++ = '('; if (!c || !(c = pplex())) { pp.token = p; error(2, "%s in #(...) argument", pptokchr(c)); break; } pp.state &= ~NOSPACE; while (c) { if (c == '(') n++; else if (c == ')' && !n--) break; else if (c == ',' && !n) break; pp.token = pp.toknxt; c = pplex(); } *pp.token++ = ')'; pp.state |= NOSPACE; } p = pp.valbuf; pp.token = token; pp.state = number; break; default: pp.token = token; while (c != ')') { if (!c) { error(2, "%s in #(...) argument", pptokchr(c)); break; } if ((c = pplex()) == T_ID && !*a) strcpy(a, pp.token); } pp.state = number; switch (op) { case V_ARGC: c = -1; for (in = pp.in; in; in = in->prev) if ((in->type == IN_MACRO || in->type == IN_MULTILINE) && (in->symbol->flags & SYM_FUNCTION)) { c = *((unsigned char*)(pp.macp->arg[0] - 2)); break; } sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", c); break; case V_BASE: p = (a = strrchr(error_info.file, '/')) ? a + 1 : error_info.file; break; case V_DATE: if (!(p = pp.date)) { time_t tm; time(&tm); a = p = ctime(&tm) + 4; *(p + 20) = 0; for (p += 7; *p = *(p + 9); p++); pp.date = p = strdup(a); } break; case V_FILE: p = error_info.file; break; case V_LINE: sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", error_info.line); break; case V_PATH: p = pp.path; break; case V_SOURCE: p = error_info.file; for (in = pp.in; in->prev; in = in->prev) if (in->prev->type == IN_FILE && in->file) p = in->file; break; case V_STDC: p = pp.valbuf; p[0] = ((pp.state & (COMPATIBILITY|TRANSITION)) || (pp.mode & (HOSTED|HOSTEDTRANSITION)) == (HOSTED|HOSTEDTRANSITION)) ? '0' : '1'; p[1] = 0; break; case V_TIME: if (!(p = pp.time)) { time_t tm; time(&tm); p = ctime(&tm) + 11; *(p + 8) = 0; pp.time = p = strdup(p); } break; case V_VERSION: p = (char*)pp.version; break; case V_DIRECTIVE: pp.state |= NEWLINE; pp.mode |= RELAX; strcpy(p = pp.valbuf, "#"); break; case V_GETENV: if (!(p = getenv(a))) p = ""; break; case V_GETMAC: p = (sym = pprefmac(a, REF_NORMAL)) ? sym->macro->value : ""; break; case V_GETOPT: sfsprintf(p = pp.valbuf, MAXTOKEN, "%ld", ppoption(a)); break; case V_GETPRD: p = (list = (struct pplist*)hashget(pp.prdtab, a)) ? list->value : ""; break; case V__PRAGMA: if ((c = pplex()) == '(') { number = pp.state; pp.state |= NOSPACE|STRIP; c = pplex(); pp.state = number; if (c == T_STRING || c == T_WSTRING) { if (!(sp = sfstropen())) error(3, "temporary buffer allocation error"); sfprintf(sp, "#%s %s\n", dirname(PRAGMA), pp.token); a = sfstruse(sp); if ((c = pplex()) == ')') { pp.state |= NEWLINE; PUSH_BUFFER(p, a, 1); } sfstrclose(sp); } } if (c != ')') error(2, "%s: (\"...\") expected", p); return; case V_FUNCTION: #define BACK(a,p) ((a>p)?*--a:(number++?0:((p=pp.outbuf+PPBUFSIZ),(a=pp.outbuf+2*PPBUFSIZ),*--a))) #define PEEK(a,p) ((a>p)?*(a-1):(number?0:*(pp.outbuf+2*PPBUFSIZ-1))) number = pp.outbuf != pp.outb; a = pp.outp; p = pp.outb; op = 0; while (c = BACK(a, p)) { if (c == '"' || c == '\'') { op = 0; while ((n = BACK(a, p)) && n != c || PEEK(a, p) == '\\'); } else if (c == '\n') { token = a; while (c = BACK(a, p)) if (c == '\n') { a = token; break; } else if (c == '#' && PEEK(a, p) == '\n') break; } else if (c == ' ') /*ignore*/; else if (c == '{') /* '}' */ op = 1; else if (op == 1) { if (c == ')') { op = 2; n = 1; } else op = 0; } else if (op == 2) { if (c == ')') n++; else if (c == '(' && !--n) op = 3; } else if (op == 3) { if (ppisidig(c)) { for (t = p, token = a, onumber = number; ppisidig(PEEK(a, p)) && a >= p; BACK(a, p)); p = pp.valbuf + 1; if (a > token) { for (; a < pp.outbuf+2*PPBUFSIZ; *p++ = *a++); a = pp.outbuf; } for (; a <= token; *p++ = *a++); *p = 0; p = pp.valbuf + 1; if (streq(p, "for") || streq(p, "if") || streq(p, "switch") || streq(p, "while")) { op = 0; p = t; number = onumber; continue; } } else op = 0; break; } } if (op == 3) p = strncpy(pp.funbuf, p, sizeof(pp.funbuf) - 1); else if (*pp.funbuf) p = pp.funbuf; else p = "__FUNCTION__"; break; default: if (pp.builtin && (a = (*pp.builtin)(pp.valbuf, p, a))) p = a; break; } break; } if (strchr(p, MARK)) { a = pp.tmpbuf; strcpy(a, p); c = p != pp.valbuf; p = pp.valbuf + c; for (;;) { if (p < pp.valbuf + MAXTOKEN - 2) switch (*p++ = *a++) { case 0: break; case MARK: *p++ = MARK; /*FALLTHROUGH*/ default: continue; } break; } p = pp.valbuf + c; } if (p == pp.valbuf) PUSH_STRING(p); else { if (p == pp.valbuf + 1) *pp.valbuf = '"'; else { if (strlen(p) > MAXTOKEN - 2) error(1, "%-.16s: builtin value truncated", p); sfsprintf(pp.valbuf, MAXTOKEN, "\"%-.*s", MAXTOKEN - 2, p); } PUSH_QUOTE(pp.valbuf, 1); } }
static char *url_replying_to(struct emailinfo *email, char *line1, /* first line of quoted text, with html */ const char *line2, /* first line of quoted text, w/o html */ const struct body *bp, int quote_num, int *quoting_msgnum, int count_quoted_lines, int maybe_reply) { String_Match match_info; char *p; int subjmatch = 0; char *anchor; struct emailinfo *ep; int statusnum = hashreplynumlookup(*quoting_msgnum, email->inreplyto, email->subject, &subjmatch); hashnumlookup(*quoting_msgnum, &ep); trio_asprintf(&anchor, "%.4dqlink%d", *quoting_msgnum, quote_num); if (statusnum != -1) { struct emailinfo *ep2; hashnumlookup(statusnum, &ep2); if (add_anchor(statusnum, *quoting_msgnum, quote_num, anchor, line1, 0, count_quoted_lines, NULL)) { char *path = get_path(ep, ep2); char *buf; trio_asprintf(&buf, "%s%.4d.%s#%s", path, statusnum, set_htmlsuffix, anchor); if (maybe_reply) set_new_reply_to(statusnum, strlen(line2)); if (*path) free(path); free(anchor); return buf; } if (strlen(line2) > 6 && (p = strstr(line2, "..."))) { char *parsed; char *tptr = (char *)emalloc(p - line2 + 1 + strlen(p + 3)); /* AUDIT biege: IOF unlikely */ strncpy(tptr, line2, p - line2); strcpy(tptr + (p - line2), p + 3); parsed = ConvURLsString(tptr, email->msgid, email->subject, email->charset); free(tptr); tptr = stripwhitespace(parsed ? parsed : ""); if (parsed) free(parsed); if (add_anchor(statusnum, *quoting_msgnum, quote_num, anchor, tptr, 1, count_quoted_lines, NULL)) { char *path = get_path(ep, ep2); char *buf; trio_asprintf(&buf, "%s%.4d.%s#%s", path, statusnum, set_htmlsuffix, anchor); free(tptr); if (maybe_reply) set_new_reply_to(statusnum, strlen(buf)); if (*path) free(path); free(anchor); return buf; } free(tptr); } } { int i; struct Push full_line; struct Push exact_line; INIT_PUSH(full_line); INIT_PUSH(exact_line); PushString(&full_line, p = stripwhitespace(line2)); free(p); PushString(&exact_line, line2); for (i = 1; i < count_quoted_lines && (bp = bp->next); ++i) { char *stripped = unquote_and_strip(bp->line); PushByte(&full_line, '\n'); PushString(&full_line, p = stripwhitespace(stripped)); free(p); free(stripped); PushString(&exact_line, unquote(bp->line)); } search_for_quote(PUSH_STRING(full_line), PUSH_STRING(exact_line), *quoting_msgnum, &match_info); free(PUSH_STRING(full_line)); free(PUSH_STRING(exact_line)); } if (match_info.msgnum >= 0) { char *parsed = ConvURLsString(match_info.last_matched_string, email->msgid, email->subject, email->charset); if (parsed) { char *parsed2 = stripwhitespace(parsed); free(parsed); if (add_anchor(match_info.msgnum, *quoting_msgnum, quote_num, anchor, parsed2, 1, count_quoted_lines, &match_info)) { struct emailinfo *ep2; char *path; char *buf; hashnumlookup(match_info.msgnum, &ep2); path = get_path(ep, ep2); trio_asprintf(&buf, "%s%.4d.%s#%s", path, match_info.msgnum, set_htmlsuffix, anchor); set_new_reply_to(match_info.msgnum, match_info.match_len_bytes); free(parsed2); if (*path) free(path); free(anchor); return buf; } free(parsed2); } if (match_info.last_matched_string) free(match_info.last_matched_string); } if (count_quoted_lines < 3 && strcmp(get_quote_prefix(), ">") && strcmp(get_quote_prefix(), " >")) /* was quote_prefix guess shaky? */ *quoting_msgnum = -1; /* msg probably doesn't have any quotes */ free(anchor); return NULL; }
static int exists(int op, char* pred, register char* args) { register int c; register int type; char* pptoken; long state; char file[MAXTOKEN + 1]; state = (pp.state & ~DISABLE); PUSH_STRING(args); pptoken = pp.token; pp.token = file; pp.state |= HEADER|PASSEOF; type = pplex(); pp.state &= ~HEADER; pp.token = pptoken; switch (type) { case T_STRING: case T_HEADER: break; default: error(1, "%s: \"...\" or <...> argument expected", pred); c = 0; goto done; } if (op == X_EXISTS) { if ((c = pplex()) == ',') { while ((c = pplex()) == T_STRING) { if (pathaccess(pp.token, file, NiL, 0, pp.path, MAXTOKEN + 1)) { pathcanon(pp.path, 0, 0); message((-2, "%s: %s found", pred, pp.path)); c = 1; goto done; } if ((c = pplex()) != ',') break; } if (c) error(1, "%s: \"...\" arguments expected", pred); strcpy(pp.path, file); message((-2, "%s: %s not found", pred, file)); c = 0; } else c = ppsearch(file, type, SEARCH_EXISTS) >= 0; } else { register struct ppfile* fp; fp = ppsetfile(file); c = fp->flags || fp->guard == INC_IGNORE; } done: while (pplex()); pp.state = state; return c; }