Skip to content

Commit d6bebd0

Browse files
authored
Merge pull request #8 from samm-git/patch-1
Use lua_pushinteger instead of lua_pushunsigned
2 parents ea49e33 + f28f577 commit d6bebd0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
LUA_VER ?= 5.2
12
SONAME = lua_sysctl
23
BUILDDIR = build
34
SOLIB = ${BUILDDIR}/sysctl.so
45
DESTDIR ?= sysctl
56

67
LDFLAGS += -shared -Wl,-soname,${SONAME}
7-
CFLAGS += -Wall -Wextra -fPIC `pkg-config --cflags lua-5.2`
8+
CFLAGS += -Wall -Wextra -fPIC `pkg-config --cflags lua-${LUA_VER}`
89

910
all: ${SOLIB}
1011

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lua version if you want to build.
2727

2828
Reading:
2929
```
30-
> require('sysctl')
30+
> sysctl = require('sysctl')
3131
> val, type = sysctl.get('kern.ostype') -- reading a string
3232
> print(val)
3333
FreeBSD
@@ -61,7 +61,7 @@ avm 420396
6161

6262
Writting:
6363
```
64-
> require('sysctl')
64+
> sysctl = require('sysctl')
6565
> sysctl.set('security.bsd.see_other_uids', 0)
6666
```
6767

src/lua_sysctl.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
#include "lauxlib.h"
6262
#include "lualib.h"
6363

64+
/*
65+
* lua 5.3+ define LUA_MAXINTEGER, but lua 5.2 does not. See
66+
* https://www.lua.org/manual/5.2/manual.html#lua_Integer
67+
*/
68+
#ifndef LUA_MAXINTEGER
69+
#define LUA_MAXINTEGER PTRDIFF_MAX
70+
#endif
6471

6572
/* NOTE: our signature of oidfmt differ from sysctl.c because we check for the
6673
buffer's size */
@@ -514,10 +521,10 @@ luaA_sysctl_get(lua_State *L)
514521
else
515522
lua_pushinteger(L, mv);
516523
} else {
517-
if (intlen > sizeof(lua_Unsigned))
524+
if (umv > LUA_MAXINTEGER)
518525
lua_pushnumber(L, umv);
519526
else
520-
lua_pushunsigned(L, umv);
527+
lua_pushinteger(L, (lua_Integer)(umv));
521528
}
522529
lua_settable(L, -3);
523530
len -= intlen;

0 commit comments

Comments
 (0)