From 41bce61b0857d69b5df8d0b66256347867b95c07 Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 27 May 2007 10:47:08 +0000 Subject: RegisterDomain replaced by Domain, which will handle destruction of the object from the LUA Stack. --- lib/LuaHttp.cc | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 6d22307..993b7a1 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -3,6 +3,61 @@ #include "LuaHandle.h" #include "LuaTask.h" +class LuaDomain; + +class LuaLuaDomain : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); + LuaLuaDomain(LuaDomain *); + protected: + virtual void pushmembers(Lua *); + LuaDomain * d; +}; + +LuaLuaDomain::LuaLuaDomain(LuaDomain * _d) : d(_d) { } + +enum LuaDomain_methods_t { + LUADOMAIN_ONTOP = 0, +}; + +enum LuaDomain_functions_t { + LUADOMAIN_NEWDOMAIN = 0, +}; + +struct lua_functypes_t LuaDomain_methods[] = { + { LUADOMAIN_ONTOP, "OnTop", 0, 0, { } }, + { -1, 0, 0, 0, 0 }, +}; + +struct lua_functypes_t LuaDomain_functions[] = { + { LUADOMAIN_NEWDOMAIN, "Domain", 2, 2, { LUA_STRING, LUA_FUNCTION } }, + { -1, 0, 0, 0, 0 }, +}; + +class sLua_LuaDomain : public Base { + public: + DECLARE_METHOD(LuaDomain, LUADOMAIN_ONTOP); + + DECLARE_FUNCTION(LuaDomain, LUADOMAIN_NEWDOMAIN); + + private: + static int LuaDomain_proceed(Lua * L, int n, LuaDomain * obj, int caller); + static int LuaDomain_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaLuaDomain::pushmembers(Lua * L) { + pushme(L, d); + + PUSH_METHOD(LuaDomain, LUADOMAIN_ONTOP); +} + +void LuaLuaDomain::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(LuaDomain); + CHECK_FUNCTIONS(LuaDomain); + + PUSH_FUNCTION(LuaDomain, LUADOMAIN_NEWDOMAIN); +} + #define DOMAIN_REGISTRY "DOMAINS_KEYS" #define export_enum(L, n) \ @@ -19,7 +74,6 @@ enum HttpResponse_method_t { enum HttpResponse_functions_t { HTTPRESPONSE_NEWHTTPRESPONSE = 0, - HTTPRESPONSE_REGISTERDOMAIN, }; struct lua_functypes_t HttpResponse_methods[] = { @@ -30,7 +84,6 @@ struct lua_functypes_t HttpResponse_methods[] = { struct lua_functypes_t HttpResponse_functions[] = { { HTTPRESPONSE_NEWHTTPRESPONSE, "HttpResponse", 0, 0, { } }, - { HTTPRESPONSE_REGISTERDOMAIN, "RegisterDomain", 2, 2, { LUA_STRING, LUA_FUNCTION } }, { -1, 0, 0, 0, 0 } }; @@ -40,7 +93,6 @@ class sLua_HttpResponse : public Base { DECLARE_METHOD(HttpResponse, HTTPRESPONSE_NEWINDEX); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_NEWHTTPRESPONSE); - DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_REGISTERDOMAIN); private: static int HttpResponse_proceed(Lua * L, int n, HttpResponse * obj, int caller); static int HttpResponse_proceed_statics(Lua * L, int n, int caller); @@ -58,7 +110,6 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { CHECK_FUNCTIONS(HttpResponse); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_NEWHTTPRESPONSE); - PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_REGISTERDOMAIN); export_enum(L, HTTP_200_OK); export_enum(L, HTTP_301_PERM_MOVED); @@ -73,6 +124,8 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { L->push(DOMAIN_REGISTRY); L->newtable(); L->settable(LUA_REGISTRYINDEX); + + LuaLuaDomain::pushstatics(L); } int sLua_HttpResponse::HttpResponse_proceed(Lua * L, int n, HttpResponse * res, int caller) { @@ -222,9 +275,36 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } r = 1; break; - case HTTPRESPONSE_REGISTERDOMAIN: - new LuaDomain(L, L->tostring(1)); } return r; } + +int sLua_LuaDomain::LuaDomain_proceed(Lua * L, int n, LuaDomain * obj, int caller) { + int r = 0; + + switch (caller) { + case LUADOMAIN_ONTOP: + obj->OnTop(); + break; + } + + return r; +} + +int sLua_LuaDomain::LuaDomain_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case LUADOMAIN_NEWDOMAIN: + { + LuaLuaDomain lld(new LuaDomain(L, L->tostring(1))); + lld.pushdestruct(L); + r = 1; + } + break; + } + + return r; +} + -- cgit v1.2.3