Lines Matching refs:L

78 static int mcp_inspector_flag_c_g(lua_State *L, int tidx) {  in mcp_inspector_flag_c_g()  argument
79 if (lua_getfield(L, tidx, "flag") != LUA_TNIL) { in mcp_inspector_flag_c_g()
81 const char *flag = lua_tolstring(L, -1, &len); in mcp_inspector_flag_c_g()
83 proxy_lua_ferror(L, "inspector step %d: 'flag' must be a single character", tidx); in mcp_inspector_flag_c_g()
86 proxy_lua_ferror(L, "inspect step %d: 'flag' must be alphanumeric", tidx); in mcp_inspector_flag_c_g()
89 proxy_lua_ferror(L, "inspector step %d: must provide 'flag' argument", tidx); in mcp_inspector_flag_c_g()
91 lua_pop(L, 1); // val or nil in mcp_inspector_flag_c_g()
95 static int mcp_inspector_flag_i_g(lua_State *L, int tidx, int sc, struct mcp_inspector *ins) { in mcp_inspector_flag_i_g() argument
99 if (lua_getfield(L, tidx, "flag") != LUA_TNIL) { in mcp_inspector_flag_i_g()
100 const char *flag = lua_tostring(L, -1); in mcp_inspector_flag_i_g()
104 lua_pop(L, 1); // val or nil in mcp_inspector_flag_i_g()
109 static int mcp_inspector_string_c_g(lua_State *L, int tidx) { in mcp_inspector_string_c_g() argument
112 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mcp_inspector_string_c_g()
113 lua_tolstring(L, -1, &len); in mcp_inspector_string_c_g()
115 proxy_lua_ferror(L, "inspector step %d: 'str' must have nonzero length", tidx); in mcp_inspector_string_c_g()
118 proxy_lua_ferror(L, "inspector step %d: must provide 'str' argument", tidx); in mcp_inspector_string_c_g()
120 lua_pop(L, 1); // val or nil in mcp_inspector_string_c_g()
125 static int mcp_inspector_string_i_g(lua_State *L, int tidx, int sc, struct mcp_inspector *ins) { in mcp_inspector_string_i_g() argument
131 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mcp_inspector_string_i_g()
132 const char *str = lua_tolstring(L, -1, &len); in mcp_inspector_string_i_g()
139 lua_pop(L, 1); // val or nil in mcp_inspector_string_i_g()
146 static int mcp_inspector_sepkey_c(lua_State *L, int tidx) { in mcp_inspector_sepkey_c() argument
147 if (lua_getfield(L, tidx, "sep") != LUA_TNIL) { in mcp_inspector_sepkey_c()
149 lua_tolstring(L, -1, &len); in mcp_inspector_sepkey_c()
151 proxy_lua_ferror(L, "inspector step %d: separator must be one character", tidx); in mcp_inspector_sepkey_c()
154 lua_pop(L, 1); // val or nil in mcp_inspector_sepkey_c()
156 if (lua_getfield(L, tidx, "pos") != LUA_TNIL) { in mcp_inspector_sepkey_c()
157 luaL_checktype(L, -1, LUA_TNUMBER); in mcp_inspector_sepkey_c()
159 lua_pop(L, 1); // val or nil in mcp_inspector_sepkey_c()
161 if (lua_getfield(L, tidx, "map") != LUA_TNIL) { in mcp_inspector_sepkey_c()
162 luaL_checktype(L, -1, LUA_TTABLE); in mcp_inspector_sepkey_c()
164 lua_pop(L, 1); // val or nil in mcp_inspector_sepkey_c()
170 static int mcp_inspector_sepkey_i(lua_State *L, int tidx, int sc, struct mcp_inspector *ins) { in mcp_inspector_sepkey_i() argument
174 if (lua_getfield(L, tidx, "sep") != LUA_TNIL) { in mcp_inspector_sepkey_i()
175 const char *sep = lua_tostring(L, -1); in mcp_inspector_sepkey_i()
181 lua_pop(L, 1); // val or nil in mcp_inspector_sepkey_i()
183 if (lua_getfield(L, tidx, "pos") != LUA_TNIL) { in mcp_inspector_sepkey_i()
184 c->pos = lua_tointeger(L, -1); in mcp_inspector_sepkey_i()
188 lua_pop(L, 1); in mcp_inspector_sepkey_i()
190 if (lua_getfield(L, tidx, "map") != LUA_TNIL) { in mcp_inspector_sepkey_i()
191 c->mapref = luaL_ref(L, LUA_REGISTRYINDEX); in mcp_inspector_sepkey_i()
194 lua_pop(L, 1); in mcp_inspector_sepkey_i()
202 static int mcp_inspector_sepkey_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s, … in mcp_inspector_sepkey_r() argument
250 lua_rawgeti(L, LUA_REGISTRYINDEX, c->mapref); in mcp_inspector_sepkey_r()
251 lua_pushlstring(L, token, tlen); in mcp_inspector_sepkey_r()
252 lua_rawget(L, -2); // pops string. in mcp_inspector_sepkey_r()
253 lua_remove(L, -2); // removes map, shifts lookup result down. in mcp_inspector_sepkey_r()
257 lua_pushlstring(L, token, tlen); in mcp_inspector_sepkey_r()
260 lua_pushnil(L); // not found. in mcp_inspector_sepkey_r()
266 static int mcp_inspector_keybegin_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s… in mcp_inspector_keybegin_r() argument
275 lua_pushboolean(L, 1); in mcp_inspector_keybegin_r()
277 lua_pushboolean(L, 0); in mcp_inspector_keybegin_r()
283 static int mcp_inspector_keyis_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s, v… in mcp_inspector_keyis_r() argument
292 lua_pushboolean(L, 1); in mcp_inspector_keyis_r()
294 lua_pushboolean(L, 0); in mcp_inspector_keyis_r()
300 static int mcp_inspector_hasflag_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s,… in mcp_inspector_hasflag_r() argument
306 lua_pushboolean(L, 1); in mcp_inspector_hasflag_r()
308 lua_pushboolean(L, 0); in mcp_inspector_hasflag_r()
318 lua_pushboolean(L, 1); in mcp_inspector_hasflag_r()
320 lua_pushboolean(L, 0); in mcp_inspector_hasflag_r()
323 proxy_lua_error(L, "inspector error: response is not meta protocol"); in mcp_inspector_hasflag_r()
330 static int mcp_inspector_flagtoken_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *… in mcp_inspector_flagtoken_r() argument
336 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagtoken_r()
340 lua_pushlstring(L, tok, tlen); // flag's token in mcp_inspector_flagtoken_r()
348 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagtoken_r()
351 lua_pushlstring(L, tok, tlen); // flag's token in mcp_inspector_flagtoken_r()
356 lua_pushboolean(L, 0); in mcp_inspector_flagtoken_r()
357 lua_pushnil(L); in mcp_inspector_flagtoken_r()
364 static int mcp_inspector_flagint_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s,… in mcp_inspector_flagint_r() argument
370 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagint_r()
373 lua_pushinteger(L, tok); in mcp_inspector_flagint_r()
375 lua_pushnil(L); in mcp_inspector_flagint_r()
384 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagint_r()
387 lua_pushinteger(L, tok); in mcp_inspector_flagint_r()
389 lua_pushnil(L); // token couldn't be converted in mcp_inspector_flagint_r()
395 lua_pushboolean(L, 0); in mcp_inspector_flagint_r()
396 lua_pushnil(L); in mcp_inspector_flagint_r()
401 static int mcp_inspector_flagstr_c(lua_State *L, int tidx) { in mcp_inspector_flagstr_c() argument
402 mcp_inspector_flag_c_g(L, tidx); in mcp_inspector_flagstr_c()
403 int size = mcp_inspector_string_c_g(L, tidx); in mcp_inspector_flagstr_c()
407 static int mcp_inspector_flagstr_i(lua_State *L, int tidx, int sc, struct mcp_inspector *ins) { in mcp_inspector_flagstr_i() argument
414 if (lua_getfield(L, tidx, "flag") != LUA_TNIL) { in mcp_inspector_flagstr_i()
415 const char *flag = lua_tostring(L, -1); in mcp_inspector_flagstr_i()
419 lua_pop(L, 1); // val or nil in mcp_inspector_flagstr_i()
421 if (lua_getfield(L, tidx, "str") != LUA_TNIL) { in mcp_inspector_flagstr_i()
422 const char *str = lua_tolstring(L, -1, &len); in mcp_inspector_flagstr_i()
429 lua_pop(L, 1); // val or nil in mcp_inspector_flagstr_i()
435 static int mcp_inspector_flagis_r(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s, … in mcp_inspector_flagis_r() argument
442 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagis_r()
447 lua_pushboolean(L, 1); in mcp_inspector_flagis_r()
449 lua_pushboolean(L, 0); in mcp_inspector_flagis_r()
458 lua_pushboolean(L, 1); // flag exists in mcp_inspector_flagis_r()
462 lua_pushboolean(L, 1); in mcp_inspector_flagis_r()
464 lua_pushboolean(L, 0); in mcp_inspector_flagis_r()
470 lua_pushboolean(L, 0); in mcp_inspector_flagis_r()
471 lua_pushnil(L); in mcp_inspector_flagis_r()
478 typedef int (*mcp_ins_c)(lua_State *L, int tidx);
479 typedef int (*mcp_ins_i)(lua_State *L, int tidx, int sc, struct mcp_inspector *ins);
480 typedef int (*mcp_ins_r)(lua_State *L, struct mcp_inspector *ins, struct mcp_ins_step *s, void *arg…
503 static enum mcp_ins_steptype mcp_inspector_steptype(lua_State *L) { in mcp_inspector_steptype() argument
504 const char *type = luaL_checkstring(L, -1); in mcp_inspector_steptype()
522 static int mcp_inspector_new(lua_State *L, enum mcp_ins_type type) { in mcp_inspector_new() argument
523 int argc = lua_gettop(L); in mcp_inspector_new()
529 luaL_checktype(L, x, LUA_TTABLE); in mcp_inspector_new()
530 if (lua_getfield(L, x, "t") != LUA_TNIL) { in mcp_inspector_new()
531 enum mcp_ins_steptype st = mcp_inspector_steptype(L); in mcp_inspector_new()
534 proxy_lua_ferror(L, "inspector step %d: step incompatible with inspector type", x); in mcp_inspector_new()
537 proxy_lua_ferror(L, "inspector step %d: unknown step type", x); in mcp_inspector_new()
539 size += e->c(L, x); in mcp_inspector_new()
541 lua_pop(L, 1); // drop 't' or nil in mcp_inspector_new()
553 struct mcp_inspector *ins = lua_newuserdatauv(L, sizeof(*ins) + extsize, 1); in mcp_inspector_new()
558 proxy_lua_error(L, "mcp.req_inspector_new: failed to allocate memory"); in mcp_inspector_new()
561 luaL_setmetatable(L, "mcp.inspector"); in mcp_inspector_new()
564 luaL_getmetatable(L, "mcp.request"); in mcp_inspector_new()
567 luaL_getmetatable(L, "mcp.response"); in mcp_inspector_new()
571 lua_setiuservalue(L, -2, 1); in mcp_inspector_new()
578 if (lua_getfield(L, x, "t") != LUA_TNIL) { in mcp_inspector_new()
579 enum mcp_ins_steptype st = mcp_inspector_steptype(L); in mcp_inspector_new()
581 mcp_ins_entries[st].i(L, x, scount, ins); in mcp_inspector_new()
584 lua_pop(L, 1); // drop t or nil in mcp_inspector_new()
589 proxy_lua_error(L, "inspector failed to properly initialize, memory not filled correctly"); in mcp_inspector_new()
596 static int mcp_ins_run(lua_State *L, struct mcp_inspector *ins, void *arg) { in mcp_ins_run() argument
602 ret += mcp_ins_entries[s->type].r(L, ins, s, arg); in mcp_ins_run()
610 int mcplib_req_inspector_new(lua_State *L) { in mcplib_req_inspector_new() argument
611 return mcp_inspector_new(L, INS_REQ); in mcplib_req_inspector_new()
614 int mcplib_res_inspector_new(lua_State *L) { in mcplib_res_inspector_new() argument
615 return mcp_inspector_new(L, INS_RES); in mcplib_res_inspector_new()
619 int mcplib_inspector_gc(lua_State *L) { in mcplib_inspector_gc() argument
620 struct mcp_inspector *ins = lua_touserdata(L, 1); in mcplib_inspector_gc()
632 luaL_unref(L, LUA_REGISTRYINDEX, s->c.sepkey.mapref); in mcplib_inspector_gc()
656 int mcplib_inspector_call(lua_State *L) { in mcplib_inspector_call() argument
658 struct mcp_inspector *ins = lua_touserdata(L, 1); in mcplib_inspector_call()
659 luaL_checktype(L, 2, LUA_TUSERDATA); in mcplib_inspector_call()
660 if (lua_checkstack(L, ins->rcount) == 0) { in mcplib_inspector_call()
661 proxy_lua_error(L, "inspector ran out of stack space for results"); in mcplib_inspector_call()
667 lua_getmetatable(L, 2); // put arg metatable on stack in mcplib_inspector_call()
668 lua_getiuservalue(L, 1, 1); // put stashed metatable on stack in mcplib_inspector_call()
669 luaL_argcheck(L, lua_rawequal(L, -1, -2), 2, in mcplib_inspector_call()
671 lua_pop(L, 2); // toss both metatables in mcplib_inspector_call()
674 void *arg = lua_touserdata(L, 2); in mcplib_inspector_call()
675 return mcp_ins_run(L, ins, arg); in mcplib_inspector_call()