From e5f454b3cee91f79f4f107b68a4708addc0a914a Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 10 May 2017 17:10:29 +0200 Subject: Improve LuaJIT support * better LuaJIT-specific headers detection * add LuaJIT-specific libraries when known * properly raise an error when attempting to transfer a LUAT_CDATA value * some compilationg warning fixes --- CHANGES | 4 ++++ src/keeper.c | 10 +++++----- src/lanes.lua | 3 +++ src/tools.c | 19 +++++++++++++------ src/tools.h | 4 +++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index a91ceae..34c35cd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ CHANGES: +CHANGE 119: BGe 10-May-17 + * Fixed some compilation warnings + * Improved LuaJIT support + CHANGE 118: trukanduk 21-Nov-16 * bumped version to 3.10.1 * objects with a metatable that contains __lanesignore are skipped during data transfers diff --git a/src/keeper.c b/src/keeper.c index 056c01e..9a7c804 100644 --- a/src/keeper.c +++ b/src/keeper.c @@ -103,7 +103,7 @@ static void fifo_push( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) for( i = count_; i >= 1; -- i) { // store in the fifo the value at the top of the stack at the specified index, popping it from the stack - lua_rawseti( L, idx, start + i); + lua_rawseti( L, idx, (int)(start + i)); } fifo_->count += count_; } @@ -115,11 +115,11 @@ static void fifo_push( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) // function assumes that there is enough data in the fifo to satisfy the request static void fifo_peek( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) { - int i; + lua_Integer i; STACK_GROW( L, count_); for( i = 0; i < count_; ++ i) { - lua_rawgeti( L, 1, fifo_->first + i); + lua_rawgeti( L, 1, (int)( fifo_->first + i)); } } @@ -134,7 +134,7 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) // skip first item, we will push it last for( i = 1; i < count_; ++ i) { - lua_Integer const at = fifo_->first + i; + int const at = (int)( fifo_->first + i); // push item on the stack lua_rawgeti( L, fifo_idx, at); // ... fifo val // remove item from the fifo @@ -143,7 +143,7 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) } // now process first item { - lua_Integer const at = fifo_->first; + int const at = (int)( fifo_->first); lua_rawgeti( L, fifo_idx, at); // ... fifo vals val lua_pushnil( L); // ... fifo vals val nil lua_rawseti( L, fifo_idx, at); // ... fifo vals val diff --git a/src/lanes.lua b/src/lanes.lua index 6cbbd65..affbd7d 100644 --- a/src/lanes.lua +++ b/src/lanes.lua @@ -220,6 +220,9 @@ lanes.configure = function( settings_) ["debug"] = true, ["bit32"] = true, -- Lua 5.2 only, ignored silently under 5.1 ["utf8"] = true, -- Lua 5.3 only, ignored silently under 5.1 and 5.2 + ["bit"] = true, -- LuaJIT only, ignored silently under PUC-Lua + ["jit"] = true, -- LuaJIT only, ignored silently under PUC-Lua + ["ffi"] = true, -- LuaJIT only, ignored silently under PUC-Lua -- ["base"] = true, ["coroutine"] = true, -- part of "base" in Lua 5.1 diff --git a/src/tools.c b/src/tools.c index 9a1c19d..c7da63e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -206,6 +206,14 @@ static const luaL_Reg libs[] = { LUA_COLIBNAME, NULL}, // Lua 5.1: part of base package #endif // LUA_VERSION_NUM { LUA_DBLIBNAME, luaopen_debug}, +#if defined LUA_JITLIBNAME // building against LuaJIT headers, add some LuaJIT-specific libs +#pragma message( "supporting JIT base libs") + { LUA_BITLIBNAME, luaopen_bit}, + { LUA_JITLIBNAME, luaopen_jit}, + { LUA_FFILIBNAME, luaopen_ffi}, +#endif // LUA_JITLIBNAME + + { LUA_DBLIBNAME, luaopen_debug}, { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) // { "base", NULL}, // ignore "base" (already acquired it) @@ -1393,25 +1401,23 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca { bool_t ret = TRUE; bool_t ignore = FALSE; + int val_type = lua_type(L, i); STACK_GROW( L2, 1); STACK_CHECK( L2); /* Skip the object if it has metatable with { __lanesignore = true } */ if( lua_getmetatable( L, i)) // ... mt { - lua_pushstring( L, "__lanesignore"); // ... mt "__lanesignore" - lua_gettable( L, -2); // ... mt ignore? - + lua_getfield( L, -1, "__lanesignore"); // ... mt ignore? if( lua_isboolean( L, -1) && lua_toboolean( L, -1)) { - ignore = TRUE; + val_type = LUA_TNIL; } - lua_pop( L, 2); // ... } /* Lets push nil to L2 if the object should be ignored */ - switch( ignore ? LUA_TNIL : lua_type( L, i)) + switch( val_type) { /* Basic types allowed both as values, and as table keys */ @@ -1664,6 +1670,7 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca /* The following types cannot be copied */ + case 10: // LuaJIT CDATA case LUA_TTHREAD: ret = FALSE; break; diff --git a/src/tools.h b/src/tools.h index a4bcf43..b869a16 100644 --- a/src/tools.h +++ b/src/tools.h @@ -17,9 +17,11 @@ #endif // For some reason, LuaJIT 64bits doesn't support lua_newstate() -#if defined(LUA_LJDIR) && (defined(__x86_64__) || defined(_M_X64)) +#if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) +//#pragma message( "LuaJIT 64 bits detected: don't propagate allocf") #define PROPAGATE_ALLOCF 0 #else // LuaJIT x64 +//#pragma message( "PUC-Lua detected: propagate allocf") #define PROPAGATE_ALLOCF 1 #endif // LuaJIT x64 #if PROPAGATE_ALLOCF -- cgit v1.2.3-55-g6feb