| 910 | } |
| 911 | |
| 912 | ts_lua_http_intercept_ctx * |
| 913 | ts_lua_create_http_intercept_ctx(lua_State *L, ts_lua_http_ctx *http_ctx, int n) |
| 914 | { |
| 915 | int i; |
| 916 | lua_State *l; |
| 917 | ts_lua_cont_info *hci; |
| 918 | ts_lua_coroutine *crt; |
| 919 | ts_lua_http_intercept_ctx *ictx; |
| 920 | |
| 921 | hci = &http_ctx->cinfo; |
| 922 | |
| 923 | ictx = TSRalloc<ts_lua_http_intercept_ctx>(); |
| 924 | memset(ictx, 0, sizeof(*ictx)); |
| 925 | |
| 926 | ictx->hctx = http_ctx; |
| 927 | |
| 928 | // create lua_thread |
| 929 | l = lua_newthread(L); |
| 930 | |
| 931 | // init the coroutine |
| 932 | crt = &ictx->cinfo.routine; |
| 933 | crt->mctx = hci->routine.mctx; |
| 934 | crt->lua = l; |
| 935 | crt->ref = luaL_ref(L, LUA_REGISTRYINDEX); |
| 936 | |
| 937 | // Todo: replace the global, context table for crt->lua |
| 938 | |
| 939 | // replicate the param |
| 940 | for (i = 0; i < n; i++) { |
| 941 | lua_pushvalue(L, i + 1); |
| 942 | } |
| 943 | |
| 944 | lua_xmove(L, l, n); // move the intercept function and params to the new lua_thread |
| 945 | |
| 946 | ts_lua_set_http_intercept_ctx(l, ictx); |
| 947 | |
| 948 | return ictx; |
| 949 | } |
| 950 | |
| 951 | void |
| 952 | ts_lua_destroy_http_intercept_ctx(ts_lua_http_intercept_ctx *ictx) |
no test coverage detected