mirror of
https://github.com/lxsang/antd-lua-plugin
synced 2024-12-27 09:58:21 +01:00
update API to support binary POST data
This commit is contained in:
parent
ae5dbf081e
commit
dfb550308d
@ -4,17 +4,37 @@
|
|||||||
// add a length field, and
|
// add a length field, and
|
||||||
void lua_new_byte_array(lua_State*L, int n)
|
void lua_new_byte_array(lua_State*L, int n)
|
||||||
{
|
{
|
||||||
size_t nbytes = sizeof(byte_array_t) + (n-1)*sizeof(unsigned char);
|
size_t nbytes = sizeof(byte_array_t) + n*sizeof(unsigned char);
|
||||||
byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes);
|
byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes);
|
||||||
|
a->data = &((char*)a)[sizeof(byte_array_t)];
|
||||||
luaL_getmetatable(L, BYTEARRAY);
|
luaL_getmetatable(L, BYTEARRAY);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
a->size = n;
|
a->size = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lua_new_light_byte_array(lua_State*L, int n, char* ptr)
|
||||||
|
{
|
||||||
|
size_t nbytes = sizeof(byte_array_t);
|
||||||
|
byte_array_t *a = (byte_array_t *)lua_newuserdata(L, nbytes);
|
||||||
|
a->size = n;
|
||||||
|
a->data = ptr;
|
||||||
|
luaL_getmetatable(L, BYTEARRAY);
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
}
|
||||||
|
|
||||||
static int l_new_barray (lua_State *L) {
|
static int l_new_barray (lua_State *L) {
|
||||||
int n = luaL_checknumber(L, 1);
|
int n = luaL_checknumber(L, 1);
|
||||||
lua_new_byte_array(L,n);
|
lua_new_byte_array(L,n);
|
||||||
return 1; /* new userdatum is already on the stack */
|
return 1; /* new userdatum is already on the stack */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_new_lightbarray (lua_State *L) {
|
||||||
|
unsigned char * ptr = lua_touserdata(L,1);
|
||||||
|
int n = luaL_checknumber(L, 2);
|
||||||
|
lua_new_light_byte_array(L,n, ptr);
|
||||||
|
return 1; /* new userdatum is already on the stack */
|
||||||
|
}
|
||||||
|
|
||||||
byte_array_t *l_check_barray (lua_State *L,int idx) {
|
byte_array_t *l_check_barray (lua_State *L,int idx) {
|
||||||
void *ud = luaL_checkudata(L, idx, BYTEARRAY);
|
void *ud = luaL_checkudata(L, idx, BYTEARRAY);
|
||||||
luaL_argcheck(L, ud != NULL, idx, "`byte array' expected");
|
luaL_argcheck(L, ud != NULL, idx, "`byte array' expected");
|
||||||
@ -78,6 +98,7 @@ static int l_barray_write(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct luaL_Reg barraylib[] = {
|
static const struct luaL_Reg barraylib[] = {
|
||||||
|
{"unew", l_new_lightbarray},
|
||||||
{"new", l_new_barray},
|
{"new", l_new_barray},
|
||||||
{"set", l_set_barray},
|
{"set", l_set_barray},
|
||||||
{"get", l_get_barray},
|
{"get", l_get_barray},
|
||||||
|
@ -22,8 +22,15 @@ static void push_dict_to_lua(lua_State* L, dictionary_t d)
|
|||||||
if(EQU(as->key,"COOKIE") || EQU(as->key,"REQUEST_HEADER") || EQU(as->key,"REQUEST_DATA") )
|
if(EQU(as->key,"COOKIE") || EQU(as->key,"REQUEST_HEADER") || EQU(as->key,"REQUEST_DATA") )
|
||||||
push_dict_to_lua(L, (dictionary_t)as->value);
|
push_dict_to_lua(L, (dictionary_t)as->value);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(strncmp(as->key,"octet-stream",12) == 0)
|
||||||
|
{
|
||||||
|
lua_pushlightuserdata(L, as->value);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
lua_pushstring(L,as->value);
|
lua_pushstring(L,as->value);
|
||||||
|
}
|
||||||
//printf("VALUE : %s\n",as->value );
|
//printf("VALUE : %s\n",as->value );
|
||||||
}
|
}
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
@ -76,6 +83,7 @@ void* lua_handle(void* data, void* meta)
|
|||||||
lua_pushlightuserdata(L, rq->client);
|
lua_pushlightuserdata(L, rq->client);
|
||||||
//lua_pushnumber(L,client);
|
//lua_pushnumber(L,client);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
|
||||||
lua_pushstring(L,"request");
|
lua_pushstring(L,"request");
|
||||||
push_dict_to_lua(L,rq->request);
|
push_dict_to_lua(L,rq->request);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// add byte array support
|
// add byte array support
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int size;
|
int size;
|
||||||
unsigned char data[1];
|
unsigned char * data;
|
||||||
} byte_array_t;
|
} byte_array_t;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
Loading…
Reference in New Issue
Block a user