Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
*.so
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ PKG_LIBDIR := $(shell $(PG_CONFIG) --pkglibdir)
# Lua specific

# General
LUA_INCDIR ?= /usr/include/lua5.1
LUALIB ?= -L/usr/local/lib -llua5.1
LUA_INCDIR ?= /usr/include/lua
LUALIB ?= -L/usr/local/lib -llua

# LuaJIT
#LUA_INCDIR = /usr/local/include/luajit-2.0
Expand Down
4 changes: 0 additions & 4 deletions pllua_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ int luaB_assert (lua_State *L) {
}

int luaB_error (lua_State *L) {
#if LUA_VERSION_NUM >= 503
int level = luaL_optinteger(L, 2, 1);
#else
int level = luaL_optint(L, 2, 1);
#endif
lua_settop(L, 1);
if (lua_isnoneornil(L, 1)){
if (lua_isnil(L, 1)){
Expand Down
30 changes: 19 additions & 11 deletions plluaapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ lua_State *luaP_newstate (int trusted) {
luaP_registerspi(L);
lua_setglobal(L, PLLUA_SPIVAR);
if (trusted) {

const char *package_keys[] = { /* to be removed */
"preload", "loadlib", "loaders", "seeall", NULL};
const char *global_keys[] = { /* to be removed */
Expand Down Expand Up @@ -874,8 +874,13 @@ void luaP_pushdatum (lua_State *L, Datum dat, Oid type) {
lua_pushinteger(L, (lua_Integer) DatumGetInt32(dat));
break;
case INT8OID:
#if LUA_VERSION_NUM >= 503
if (sizeof(lua_Integer) >= 8)
lua_pushinteger(L, (lua_Integer) DatumGetInt64(dat));
else
#endif
setInt64lua(L,(DatumGetInt64(dat)));
break;
break;
case TEXTOID:
lua_pushstring(L, text2string(dat));
break;
Expand Down Expand Up @@ -1101,18 +1106,21 @@ Datum luaP_todatum (lua_State *L, Oid type, int typmod, bool *isnull, int idx) {
dat = Int32GetDatum(lua_tointeger(L, idx));
break;
case INT8OID:
#if LUA_VERSION_NUM >= 503
if (sizeof(lua_Integer) >= 8)
dat = Int64GetDatum(lua_tointeger(L, idx));
else
#endif
#ifdef USE_FLOAT8_BYVAL
dat = Int64GetDatum(get64lua(L, idx));
break;
dat = Int64GetDatum(get64lua(L, idx));
#else
{
int64* value = (int64*)SPI_palloc(sizeof(int64));
*value = get64lua(L, idx);
dat = PointerGetDatum(value);
break;
}
{
int64* value = (int64*)SPI_palloc(sizeof(int64));
*value = get64lua(L, idx);
dat = PointerGetDatum(value);
}
#endif

break;
case TEXTOID: {
const char *s = lua_tostring(L, idx);
if (s == NULL) elog(ERROR,
Expand Down
24 changes: 0 additions & 24 deletions plluaspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,7 @@ static int luaP_cursortostring (lua_State *L) {

static int luaP_cursorfetch (lua_State *L) {
luaP_Cursor *c = (luaP_Cursor *) luaP_checkudata(L, 1, PLLUA_CURSORMT);
#if LUA_VERSION_NUM >= 503
SPI_cursor_fetch(c->cursor, 1, luaL_optinteger(L, 2, FETCH_ALL));
#else
SPI_cursor_fetch(c->cursor, 1, luaL_optlong(L, 2, FETCH_ALL));
#endif
if (SPI_processed > 0) /* any rows? */
luaP_pushtuptable(L, c->cursor);
else
Expand All @@ -779,23 +775,15 @@ static int luaP_cursorfetch (lua_State *L) {

static int luaP_cursormove (lua_State *L) {
luaP_Cursor *c = (luaP_Cursor *) luaP_checkudata(L, 1, PLLUA_CURSORMT);
#if LUA_VERSION_NUM >= 503
SPI_cursor_move(c->cursor, 1, luaL_optinteger(L, 2, 0));
#else
SPI_cursor_move(c->cursor, 1, luaL_optlong(L, 2, 0));
#endif
return 0;
}

#if PG_VERSION_NUM >= 80300
static int luaP_cursorposfetch (lua_State *L) {
luaP_Cursor *c = (luaP_Cursor *) luaP_checkudata(L, 1, PLLUA_CURSORMT);
FetchDirection fd = (lua_toboolean(L, 3)) ? FETCH_RELATIVE : FETCH_ABSOLUTE;
#if LUA_VERSION_NUM >= 503
SPI_scroll_cursor_fetch(c->cursor, fd, luaL_optinteger(L, 2, FETCH_ALL));
#else
SPI_scroll_cursor_fetch(c->cursor, fd, luaL_optlong(L, 2, FETCH_ALL));
#endif
if (SPI_processed > 0) /* any rows? */
luaP_pushtuptable(L, c->cursor);
else
Expand All @@ -806,11 +794,7 @@ static int luaP_cursorposfetch (lua_State *L) {
static int luaP_cursorposmove (lua_State *L) {
luaP_Cursor *c = (luaP_Cursor *) luaP_checkudata(L, 1, PLLUA_CURSORMT);
FetchDirection fd = (lua_toboolean(L, 3)) ? FETCH_RELATIVE : FETCH_ABSOLUTE;
#if LUA_VERSION_NUM >= 503
SPI_scroll_cursor_move(c->cursor, fd, luaL_optinteger(L, 2, 0));
#else
SPI_scroll_cursor_move(c->cursor, fd, luaL_optlong(L, 2, 0));
#endif
return 0;
}
#endif
Expand Down Expand Up @@ -844,11 +828,7 @@ static int luaP_plantostring (lua_State *L) {
static int luaP_executeplan (lua_State *L) {
luaP_Plan *p = (luaP_Plan *) luaP_checkudata(L, 1, PLLUA_PLANMT);
bool ro = (bool) lua_toboolean(L, 3);
#if LUA_VERSION_NUM >= 503
long c = luaL_optinteger(L, 4, 0);
#else
long c = luaL_optlong(L, 4, 0);
#endif
int result = -1;
Datum *values = NULL;
char *nulls = NULL;
Expand Down Expand Up @@ -1003,11 +983,7 @@ static int luaP_execute (lua_State *L) {
PLLUA_PG_CATCH_RETHROW(
result = SPI_execute(luaL_checkstring(L, 1),
(bool) lua_toboolean(L, 2),
#if LUA_VERSION_NUM >= 503
luaL_optinteger(L, 3, 0));
#else
luaL_optlong(L, 3, 0));
#endif
);
if (result < 0)
return luaL_error(L, "SPI_execute_plan error: %d", result);
Expand Down