forked from zhaozg/lua-openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
73 lines (65 loc) · 1.41 KB
/
util.c
File metadata and controls
73 lines (65 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/***
util module with internal utility functions for lua-openssl
This module provides internal utility functions for value management,
memory handling, and registry operations used throughout the
lua-openssl library.
*/
#include "private.h"
int
openssl_newvalue(lua_State *L, const void *p)
{
lua_rawgetp(L, LUA_REGISTRYINDEX, p);
if (lua_isnil(L, -1)) {
lua_newtable(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, p);
}
lua_pop(L, 1);
return 0;
}
int
openssl_freevalue(lua_State *L, const void *p)
{
lua_pushnil(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, p);
return 0;
}
int
openssl_valueset(lua_State *L, const void *p, const char *field)
{
lua_rawgetp(L, LUA_REGISTRYINDEX, p);
lua_pushstring(L, field);
lua_pushvalue(L, -3);
lua_rawset(L, -3);
lua_pop(L, 2);
return 0;
}
int
openssl_valueget(lua_State *L, const void *p, const char *field)
{
lua_rawgetp(L, LUA_REGISTRYINDEX, p);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, field);
lua_rawget(L, -2);
lua_remove(L, -2);
}
return lua_type(L, -1);
}
int
openssl_valueseti(lua_State *L, const void *p, int i)
{
lua_rawgetp(L, LUA_REGISTRYINDEX, p);
lua_pushvalue(L, -2);
lua_rawseti(L, -2, i);
lua_pop(L, 2);
return 0;
}
int
openssl_valuegeti(lua_State *L, const void *p, int i)
{
lua_rawgetp(L, LUA_REGISTRYINDEX, p);
if (!lua_isnil(L, -1)) {
lua_rawgeti(L, -1, i);
lua_remove(L, -2);
}
return lua_type(L, -1);
}