diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-31 21:56:42 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-31 21:56:42 +0100 |
commit | 968f41ba511f8f74377b1a1c7b61ff759ebe3078 (patch) | |
tree | c52f95f94444254cd93e8e3460f7013eaab18b41 /source/ManualBindings.cpp | |
parent | Slight code cleanup, no big changes (diff) | |
download | cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar.gz cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar.bz2 cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar.lz cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar.xz cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.tar.zst cuberite-968f41ba511f8f74377b1a1c7b61ff759ebe3078.zip |
Diffstat (limited to '')
-rw-r--r-- | source/ManualBindings.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index 06a148b91..7e2e45855 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -11,6 +11,8 @@ #include "cWebPlugin_Lua.h"
#include "cLuaCommandBinder.h"
#include "cPlayer.h"
+#include "cWebAdmin.h"
+#include "cStringMap.h"
#include "md5/md5.h"
extern std::vector<std::string> StringSplit(std::string str, std::string delim);
@@ -266,6 +268,54 @@ static int tolua_md5(lua_State* tolua_S) return 1;
}
+static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, std::string >& a_StringStringMap )
+{
+ lua_newtable(tolua_S);
+ int top = lua_gettop(tolua_S);
+
+ for( std::map< std::string, std::string >::iterator it = a_StringStringMap.begin(); it != a_StringStringMap.end(); ++it )
+ {
+ const char* key = it->first.c_str();
+ const char* value = it->second.c_str();
+ lua_pushstring(tolua_S, key);
+ lua_pushstring(tolua_S, value);
+ lua_settable(tolua_S, top);
+ }
+
+ return 1;
+}
+
+static int tolua_get_HTTPRequest_Params(lua_State* tolua_S)
+{
+ HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0);
+ return tolua_push_StringStringMap(tolua_S, self->Params);
+}
+
+static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S)
+{
+ HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0);
+ return tolua_push_StringStringMap(tolua_S, self->PostParams);
+}
+
+static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S)
+{
+ HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0);
+ std::map< std::string, HTTPFormData >& FormData = self->FormData;
+
+ lua_newtable(tolua_S);
+ int top = lua_gettop(tolua_S);
+
+ for( std::map< std::string, HTTPFormData >::iterator it = FormData.begin(); it != FormData.end(); ++it )
+ {
+ lua_pushstring(tolua_S, it->first.c_str() );
+ tolua_pushusertype(tolua_S, &(it->second), "HTTPFormData" );
+ //lua_pushlstring(tolua_S, it->second.Value.c_str(), it->second.Value.size() ); // Might contain binary data
+ lua_settable(tolua_S, top);
+ }
+
+ return 1;
+}
+
void ManualBindings::Bind( lua_State* tolua_S )
{
tolua_beginmodule(tolua_S,NULL);
@@ -293,6 +343,15 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_beginmodule(tolua_S,"cWebPlugin_Lua");
tolua_function(tolua_S,"AddTab",tolua_cWebPlugin_Lua_AddTab);
tolua_endmodule(tolua_S);
+
+ tolua_cclass(tolua_S,"HTTPRequest","HTTPRequest","",NULL);
+ tolua_beginmodule(tolua_S,"HTTPRequest");
+ //tolua_variable(tolua_S,"Method",tolua_get_HTTPRequest_Method,tolua_set_HTTPRequest_Method);
+ //tolua_variable(tolua_S,"Path",tolua_get_HTTPRequest_Path,tolua_set_HTTPRequest_Path);
+ tolua_variable(tolua_S,"Params",tolua_get_HTTPRequest_Params,0);
+ tolua_variable(tolua_S,"PostParams",tolua_get_HTTPRequest_PostParams,0);
+ tolua_variable(tolua_S,"FormData",tolua_get_HTTPRequest_FormData,0);
+ tolua_endmodule(tolua_S);
tolua_function(tolua_S,"md5",tolua_md5);
|