| 133 | } |
| 134 | |
| 135 | static int lua_http_post(lua_State* L) { |
| 136 | // http_post(url, post_body [, headers]) → body, status_code |
| 137 | size_t bodyLen = 0; |
| 138 | const char* body = luaL_checklstring(L, 2, &bodyLen); |
| 139 | auto hdrs = LuaHeadersToWstr(L, lua_gettop(L) >= 3 ? 3 : -1); |
| 140 | auto r = OSTPlatform::Http::Execute(L"POST", luaL_checkstring(L, 1), |
| 141 | body, static_cast<uint32_t>(bodyLen), |
| 142 | hdrs.empty() ? nullptr : hdrs.c_str()); |
| 143 | if (r.ok) { |
| 144 | lua_pushstring(L, r.body.c_str()); |
| 145 | lua_pushinteger(L, r.status); |
| 146 | } else { |
| 147 | lua_pushnil(L); |
| 148 | lua_pushstring(L, "HTTP request failed"); |
| 149 | } |
| 150 | return 2; |
| 151 | } |
| 152 | |
| 153 | // ── Case-insensitive global function lookup ───────────────── |
| 154 | // __index metamethod on _G: when a global name isn't found, |
nothing calls this directly
no test coverage detected