mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
use new lua userdata api
This commit is contained in:
@@ -317,7 +317,7 @@ _lctx_ciphers(lua_State* L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lnew_ctx(lua_State* L) {
|
lnew_ctx(lua_State* L) {
|
||||||
struct ssl_ctx* ctx_p = (struct ssl_ctx*)lua_newuserdata(L, sizeof(*ctx_p));
|
struct ssl_ctx* ctx_p = (struct ssl_ctx*)lua_newuserdatauv(L, sizeof(*ctx_p), 0);
|
||||||
ctx_p->ctx = SSL_CTX_new(SSLv23_method());
|
ctx_p->ctx = SSL_CTX_new(SSLv23_method());
|
||||||
if(!ctx_p->ctx) {
|
if(!ctx_p->ctx) {
|
||||||
unsigned int err = ERR_get_error();
|
unsigned int err = ERR_get_error();
|
||||||
@@ -345,12 +345,12 @@ lnew_ctx(lua_State* L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lnew_tls(lua_State* L) {
|
lnew_tls(lua_State* L) {
|
||||||
struct tls_context* tls_p = (struct tls_context*)lua_newuserdata(L, sizeof(*tls_p));
|
struct tls_context* tls_p = (struct tls_context*)lua_newuserdatauv(L, sizeof(*tls_p), 1);
|
||||||
tls_p->is_close = false;
|
tls_p->is_close = false;
|
||||||
const char* method = luaL_optstring(L, 1, "nil");
|
const char* method = luaL_optstring(L, 1, "nil");
|
||||||
struct ssl_ctx* ctx_p = _check_sslctx(L, 2);
|
struct ssl_ctx* ctx_p = _check_sslctx(L, 2);
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
lua_setuservalue(L, -2); // set ssl_ctx associated to tls_context
|
lua_setiuservalue(L, -2, 1); // set ssl_ctx associated to tls_context
|
||||||
|
|
||||||
if(strcmp(method, "client") == 0) {
|
if(strcmp(method, "client") == 0) {
|
||||||
_init_client_context(L, tls_p, ctx_p);
|
_init_client_context(L, tls_p, ctx_p);
|
||||||
|
|||||||
@@ -818,7 +818,7 @@ lmakeindex(lua_State *L) {
|
|||||||
lua_rawset(L,-3);
|
lua_rawset(L,-3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_setuservalue(L,1);
|
lua_setiuservalue(L,1,1);
|
||||||
lua_settop(L,1);
|
lua_settop(L,1);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -862,7 +862,7 @@ replace_object(lua_State *L, int type, struct bson * bs) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lreplace(lua_State *L) {
|
lreplace(lua_State *L) {
|
||||||
lua_getuservalue(L,1);
|
lua_getiuservalue(L,1,1);
|
||||||
if (!lua_istable(L,-1)) {
|
if (!lua_istable(L,-1)) {
|
||||||
return luaL_error(L, "call makeindex first");
|
return luaL_error(L, "call makeindex first");
|
||||||
}
|
}
|
||||||
@@ -954,7 +954,7 @@ encode_bson(lua_State *L) {
|
|||||||
} else {
|
} else {
|
||||||
pack_simple_dict(L, b, 0);
|
pack_simple_dict(L, b, 0);
|
||||||
}
|
}
|
||||||
void * ud = lua_newuserdata(L, b->size);
|
void * ud = lua_newuserdatauv(L, b->size, 1);
|
||||||
memcpy(ud, b->ptr, b->size);
|
memcpy(ud, b->ptr, b->size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -984,7 +984,7 @@ encode_bson_byorder(lua_State *L) {
|
|||||||
lua_settop(L, --n);
|
lua_settop(L, --n);
|
||||||
pack_ordered_dict(L, b, n, 0);
|
pack_ordered_dict(L, b, n, 0);
|
||||||
lua_settop(L,0);
|
lua_settop(L,0);
|
||||||
void * ud = lua_newuserdata(L, b->size);
|
void * ud = lua_newuserdatauv(L, b->size, 1);
|
||||||
memcpy(ud, b->ptr, b->size);
|
memcpy(ud, b->ptr, b->size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ ldesencode(lua_State *L) {
|
|||||||
uint8_t tmp[SMALL_CHUNK];
|
uint8_t tmp[SMALL_CHUNK];
|
||||||
uint8_t *buffer = tmp;
|
uint8_t *buffer = tmp;
|
||||||
if (chunksz > SMALL_CHUNK) {
|
if (chunksz > SMALL_CHUNK) {
|
||||||
buffer = lua_newuserdata(L, chunksz);
|
buffer = lua_newuserdatauv(L, chunksz, 0);
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<(int)textsz-7;i+=8) {
|
for (i=0;i<(int)textsz-7;i+=8) {
|
||||||
@@ -503,7 +503,7 @@ ldesdecode(lua_State *L) {
|
|||||||
uint8_t tmp[SMALL_CHUNK];
|
uint8_t tmp[SMALL_CHUNK];
|
||||||
uint8_t *buffer = tmp;
|
uint8_t *buffer = tmp;
|
||||||
if (textsz > SMALL_CHUNK) {
|
if (textsz > SMALL_CHUNK) {
|
||||||
buffer = lua_newuserdata(L, textsz);
|
buffer = lua_newuserdatauv(L, textsz, 0);
|
||||||
}
|
}
|
||||||
for (i=0;i<textsz;i+=8) {
|
for (i=0;i<textsz;i+=8) {
|
||||||
des_crypt(SK, text+i, buffer+i);
|
des_crypt(SK, text+i, buffer+i);
|
||||||
@@ -558,7 +558,7 @@ ltohex(lua_State *L) {
|
|||||||
char tmp[SMALL_CHUNK];
|
char tmp[SMALL_CHUNK];
|
||||||
char *buffer = tmp;
|
char *buffer = tmp;
|
||||||
if (sz > SMALL_CHUNK/2) {
|
if (sz > SMALL_CHUNK/2) {
|
||||||
buffer = lua_newuserdata(L, sz * 2);
|
buffer = lua_newuserdatauv(L, sz * 2, 0);
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<sz;i++) {
|
for (i=0;i<sz;i++) {
|
||||||
@@ -581,7 +581,7 @@ lfromhex(lua_State *L) {
|
|||||||
char tmp[SMALL_CHUNK];
|
char tmp[SMALL_CHUNK];
|
||||||
char *buffer = tmp;
|
char *buffer = tmp;
|
||||||
if (sz > SMALL_CHUNK*2) {
|
if (sz > SMALL_CHUNK*2) {
|
||||||
buffer = lua_newuserdata(L, sz / 2);
|
buffer = lua_newuserdatauv(L, sz / 2, 0);
|
||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<sz;i+=2) {
|
for (i=0;i<sz;i+=2) {
|
||||||
@@ -898,7 +898,7 @@ lb64encode(lua_State *L) {
|
|||||||
char tmp[SMALL_CHUNK];
|
char tmp[SMALL_CHUNK];
|
||||||
char *buffer = tmp;
|
char *buffer = tmp;
|
||||||
if (encode_sz > SMALL_CHUNK) {
|
if (encode_sz > SMALL_CHUNK) {
|
||||||
buffer = lua_newuserdata(L, encode_sz);
|
buffer = lua_newuserdatauv(L, encode_sz, 0);
|
||||||
}
|
}
|
||||||
int i,j;
|
int i,j;
|
||||||
j=0;
|
j=0;
|
||||||
@@ -953,7 +953,7 @@ lb64decode(lua_State *L) {
|
|||||||
char tmp[SMALL_CHUNK];
|
char tmp[SMALL_CHUNK];
|
||||||
char *buffer = tmp;
|
char *buffer = tmp;
|
||||||
if (decode_sz > SMALL_CHUNK) {
|
if (decode_sz > SMALL_CHUNK) {
|
||||||
buffer = lua_newuserdata(L, decode_sz);
|
buffer = lua_newuserdatauv(L, decode_sz, 0);
|
||||||
}
|
}
|
||||||
int i,j;
|
int i,j;
|
||||||
int output = 0;
|
int output = 0;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ create_proxy(lua_State *L, const void *data, int index) {
|
|||||||
// NODECACHE, table, PROXYCACHE
|
// NODECACHE, table, PROXYCACHE
|
||||||
lua_pushvalue(L, -2);
|
lua_pushvalue(L, -2);
|
||||||
// NODECACHE, table, PROXYCACHE, table
|
// NODECACHE, table, PROXYCACHE, table
|
||||||
struct proxy * p = lua_newuserdata(L, sizeof(struct proxy));
|
struct proxy * p = lua_newuserdatauv(L, sizeof(struct proxy), 0);
|
||||||
// NODECACHE, table, PROXYCACHE, table, proxy
|
// NODECACHE, table, PROXYCACHE, table, proxy
|
||||||
p->data = data;
|
p->data = data;
|
||||||
p->index = index;
|
p->index = index;
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ new_channel(lua_State *L, struct channel *c) {
|
|||||||
luaL_error(L, "new channel failed");
|
luaL_error(L, "new channel failed");
|
||||||
// never go here
|
// never go here
|
||||||
}
|
}
|
||||||
struct channel_box * cb = lua_newuserdata(L, sizeof(*cb));
|
struct channel_box * cb = lua_newuserdatauv(L, sizeof(*cb), 0);
|
||||||
cb->c = c;
|
cb->c = c;
|
||||||
if (luaL_newmetatable(L, METANAME)) {
|
if (luaL_newmetatable(L, METANAME)) {
|
||||||
luaL_Reg l[]={
|
luaL_Reg l[]={
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ static struct queue *
|
|||||||
get_queue(lua_State *L) {
|
get_queue(lua_State *L) {
|
||||||
struct queue *q = lua_touserdata(L,1);
|
struct queue *q = lua_touserdata(L,1);
|
||||||
if (q == NULL) {
|
if (q == NULL) {
|
||||||
q = lua_newuserdata(L, sizeof(struct queue));
|
q = lua_newuserdatauv(L, sizeof(struct queue), 0);
|
||||||
q->cap = QUEUESIZE;
|
q->cap = QUEUESIZE;
|
||||||
q->head = 0;
|
q->head = 0;
|
||||||
q->tail = 0;
|
q->tail = 0;
|
||||||
@@ -132,7 +132,7 @@ get_queue(lua_State *L) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
expand_queue(lua_State *L, struct queue *q) {
|
expand_queue(lua_State *L, struct queue *q) {
|
||||||
struct queue *nq = lua_newuserdata(L, sizeof(struct queue) + q->cap * sizeof(struct netpack));
|
struct queue *nq = lua_newuserdatauv(L, sizeof(struct queue) + q->cap * sizeof(struct netpack), 0);
|
||||||
nq->cap = q->cap + QUEUESIZE;
|
nq->cap = q->cap + QUEUESIZE;
|
||||||
nq->head = 0;
|
nq->head = 0;
|
||||||
nq->tail = q->cap;
|
nq->tail = q->cap;
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ convert_stringmap(struct context *ctx, struct table *tbl) {
|
|||||||
lua_checkstack(L, ctx->string_index + LUA_MINSTACK);
|
lua_checkstack(L, ctx->string_index + LUA_MINSTACK);
|
||||||
lua_settop(L, ctx->string_index + 1);
|
lua_settop(L, ctx->string_index + 1);
|
||||||
lua_pushvalue(L, 1);
|
lua_pushvalue(L, 1);
|
||||||
struct state * s = lua_newuserdata(L, sizeof(*s));
|
struct state * s = lua_newuserdatauv(L, sizeof(*s), 1);
|
||||||
s->dirty = 0;
|
s->dirty = 0;
|
||||||
s->ref = 0;
|
s->ref = 0;
|
||||||
s->root = tbl;
|
s->root = tbl;
|
||||||
@@ -678,7 +678,7 @@ lboxconf(lua_State *L) {
|
|||||||
struct state * s = lua_touserdata(tbl->L, 1);
|
struct state * s = lua_touserdata(tbl->L, 1);
|
||||||
ATOM_INC(&s->ref);
|
ATOM_INC(&s->ref);
|
||||||
|
|
||||||
struct ctrl * c = lua_newuserdata(L, sizeof(*c));
|
struct ctrl * c = lua_newuserdatauv(L, sizeof(*c), 1);
|
||||||
c->root = tbl;
|
c->root = tbl;
|
||||||
c->update = NULL;
|
c->update = NULL;
|
||||||
if (luaL_newmetatable(L, "confctrl")) {
|
if (luaL_newmetatable(L, "confctrl")) {
|
||||||
@@ -742,7 +742,7 @@ lneedupdate(lua_State *L) {
|
|||||||
struct ctrl * c = lua_touserdata(L, 1);
|
struct ctrl * c = lua_touserdata(L, 1);
|
||||||
if (c->update) {
|
if (c->update) {
|
||||||
lua_pushlightuserdata(L, c->update);
|
lua_pushlightuserdata(L, c->update);
|
||||||
lua_getuservalue(L, 1);
|
lua_getiuservalue(L, 1, 1);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -759,7 +759,7 @@ lupdate(lua_State *L) {
|
|||||||
return luaL_error(L, "You should update a new object");
|
return luaL_error(L, "You should update a new object");
|
||||||
}
|
}
|
||||||
lua_settop(L, 3);
|
lua_settop(L, 3);
|
||||||
lua_setuservalue(L, 1);
|
lua_setiuservalue(L, 1, 1);
|
||||||
c->update = n;
|
c->update = n;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ get_size(lua_State *L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
box_state(lua_State *L, lua_State *mL) {
|
box_state(lua_State *L, lua_State *mL) {
|
||||||
struct state_ud *ud = (struct state_ud *)lua_newuserdata(L, sizeof(*ud));
|
struct state_ud *ud = (struct state_ud *)lua_newuserdatauv(L, sizeof(*ud), 0);
|
||||||
ud->L = mL;
|
ud->L = mL;
|
||||||
if (luaL_newmetatable(L, "BOXMATRIXSTATE")) {
|
if (luaL_newmetatable(L, "BOXMATRIXSTATE")) {
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ lfreepool(lua_State *L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lnewpool(lua_State *L, int sz) {
|
lnewpool(lua_State *L, int sz) {
|
||||||
struct buffer_node * pool = lua_newuserdata(L, sizeof(struct buffer_node) * sz);
|
struct buffer_node * pool = lua_newuserdatauv(L, sizeof(struct buffer_node) * sz, 0);
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<sz;i++) {
|
for (i=0;i<sz;i++) {
|
||||||
pool[i].msg = NULL;
|
pool[i].msg = NULL;
|
||||||
@@ -71,7 +71,7 @@ lnewpool(lua_State *L, int sz) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lnewbuffer(lua_State *L) {
|
lnewbuffer(lua_State *L) {
|
||||||
struct socket_buffer * sb = lua_newuserdata(L, sizeof(*sb));
|
struct socket_buffer * sb = lua_newuserdatauv(L, sizeof(*sb), 0);
|
||||||
sb->size = 0;
|
sb->size = 0;
|
||||||
sb->offset = 0;
|
sb->offset = 0;
|
||||||
sb->head = NULL;
|
sb->head = NULL;
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ lnewwriter(lua_State *L) {
|
|||||||
msg = skynet_malloc(sz);
|
msg = skynet_malloc(sz);
|
||||||
memcpy(msg, tmp, sz);
|
memcpy(msg, tmp, sz);
|
||||||
}
|
}
|
||||||
struct boxstm * box = lua_newuserdata(L, sizeof(*box));
|
struct boxstm * box = lua_newuserdatauv(L, sizeof(*box), 0);
|
||||||
box->obj = stm_new(msg,sz);
|
box->obj = stm_new(msg,sz);
|
||||||
lua_pushvalue(L, lua_upvalueindex(1));
|
lua_pushvalue(L, lua_upvalueindex(1));
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
@@ -182,7 +182,7 @@ struct boxreader {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lnewreader(lua_State *L) {
|
lnewreader(lua_State *L) {
|
||||||
struct boxreader * box = lua_newuserdata(L, sizeof(*box));
|
struct boxreader * box = lua_newuserdatauv(L, sizeof(*box), 0);
|
||||||
box->obj = lua_touserdata(L, 1);
|
box->obj = lua_touserdata(L, 1);
|
||||||
box->lastcopy = NULL;
|
box->lastcopy = NULL;
|
||||||
lua_pushvalue(L, lua_upvalueindex(1));
|
lua_pushvalue(L, lua_upvalueindex(1));
|
||||||
|
|||||||
Reference in New Issue
Block a user