use new lua userdata api

This commit is contained in:
Cloud Wu
2020-10-10 19:19:33 +08:00
parent 623d8182eb
commit a87b039c6d
10 changed files with 26 additions and 26 deletions

View File

@@ -317,7 +317,7 @@ _lctx_ciphers(lua_State* L) {
static int
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());
if(!ctx_p->ctx) {
unsigned int err = ERR_get_error();
@@ -345,12 +345,12 @@ lnew_ctx(lua_State* L) {
static int
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;
const char* method = luaL_optstring(L, 1, "nil");
struct ssl_ctx* ctx_p = _check_sslctx(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) {
_init_client_context(L, tls_p, ctx_p);