1
0

init commit

This commit is contained in:
2022-11-01 23:31:14 +08:00
commit 57c2c6a22e
26 changed files with 2208 additions and 0 deletions

41
envoy/main.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "envoy.h"
int callLua(lua_State* state, const char *func)
{
lua::LuaDeathRef<lua::StreamHandleWrapper> handle;
lua_getglobal(state, func);
if (lua_isfunction(state, -1)) {
handle.reset(lua::StreamHandleWrapper::create(state), true);
lua_call(state, 1, 0);
}
lua_pop(state, 1);
return 0;
}
int main(int argc, char *argv[])
{
if (argc < 1) {
printf("usage: envoy-apisix [lua file]\n");
return 0;
}
lua_State* state = luaL_newstate();
luaL_openlibs(state);
lua::BufferWrapper::registerType(state);
lua::HeaderMapIterator::registerType(state);
lua::HeaderMapWrapper::registerType(state);
lua::MetadataMapWrapper::registerType(state);
lua::MetadataMapIterator::registerType(state);
lua::StreamInfoWrapper::registerType(state);
lua::StreamHandleWrapper::registerType(state);
if (luaL_dofile(state, argv[1])) {
printf("script load error: %s\n", lua_tostring(state, -1));
return 0;
}
callLua(state, "envoy_on_request");
lua_close(state);
return 0;
}