diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2017-05-10 17:10:29 +0200 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2017-05-10 17:10:29 +0200 |
commit | e5f454b3cee91f79f4f107b68a4708addc0a914a (patch) | |
tree | e8d3c53937659b2f615870b9294a0d5e0dfa7a30 | |
parent | 0a064da8d02d0863463583e4f693462ef7725c2f (diff) | |
download | lanes-e5f454b3cee91f79f4f107b68a4708addc0a914a.tar.gz lanes-e5f454b3cee91f79f4f107b68a4708addc0a914a.tar.bz2 lanes-e5f454b3cee91f79f4f107b68a4708addc0a914a.zip |
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
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | src/keeper.c | 10 | ||||
-rw-r--r-- | src/lanes.lua | 3 | ||||
-rw-r--r-- | src/tools.c | 19 | ||||
-rw-r--r-- | src/tools.h | 4 |
5 files changed, 28 insertions, 12 deletions
@@ -1,5 +1,9 @@ | |||
1 | CHANGES: | 1 | CHANGES: |
2 | 2 | ||
3 | CHANGE 119: BGe 10-May-17 | ||
4 | * Fixed some compilation warnings | ||
5 | * Improved LuaJIT support | ||
6 | |||
3 | CHANGE 118: trukanduk 21-Nov-16 | 7 | CHANGE 118: trukanduk 21-Nov-16 |
4 | * bumped version to 3.10.1 | 8 | * bumped version to 3.10.1 |
5 | * objects with a metatable that contains __lanesignore are skipped during data transfers | 9 | * 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_) | |||
103 | for( i = count_; i >= 1; -- i) | 103 | for( i = count_; i >= 1; -- i) |
104 | { | 104 | { |
105 | // store in the fifo the value at the top of the stack at the specified index, popping it from the stack | 105 | // store in the fifo the value at the top of the stack at the specified index, popping it from the stack |
106 | lua_rawseti( L, idx, start + i); | 106 | lua_rawseti( L, idx, (int)(start + i)); |
107 | } | 107 | } |
108 | fifo_->count += count_; | 108 | fifo_->count += count_; |
109 | } | 109 | } |
@@ -115,11 +115,11 @@ static void fifo_push( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) | |||
115 | // function assumes that there is enough data in the fifo to satisfy the request | 115 | // function assumes that there is enough data in the fifo to satisfy the request |
116 | static void fifo_peek( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) | 116 | static void fifo_peek( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) |
117 | { | 117 | { |
118 | int i; | 118 | lua_Integer i; |
119 | STACK_GROW( L, count_); | 119 | STACK_GROW( L, count_); |
120 | for( i = 0; i < count_; ++ i) | 120 | for( i = 0; i < count_; ++ i) |
121 | { | 121 | { |
122 | lua_rawgeti( L, 1, fifo_->first + i); | 122 | lua_rawgeti( L, 1, (int)( fifo_->first + i)); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
@@ -134,7 +134,7 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) | |||
134 | // skip first item, we will push it last | 134 | // skip first item, we will push it last |
135 | for( i = 1; i < count_; ++ i) | 135 | for( i = 1; i < count_; ++ i) |
136 | { | 136 | { |
137 | lua_Integer const at = fifo_->first + i; | 137 | int const at = (int)( fifo_->first + i); |
138 | // push item on the stack | 138 | // push item on the stack |
139 | lua_rawgeti( L, fifo_idx, at); // ... fifo val | 139 | lua_rawgeti( L, fifo_idx, at); // ... fifo val |
140 | // remove item from the fifo | 140 | // remove item from the fifo |
@@ -143,7 +143,7 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo_, lua_Integer count_) | |||
143 | } | 143 | } |
144 | // now process first item | 144 | // now process first item |
145 | { | 145 | { |
146 | lua_Integer const at = fifo_->first; | 146 | int const at = (int)( fifo_->first); |
147 | lua_rawgeti( L, fifo_idx, at); // ... fifo vals val | 147 | lua_rawgeti( L, fifo_idx, at); // ... fifo vals val |
148 | lua_pushnil( L); // ... fifo vals val nil | 148 | lua_pushnil( L); // ... fifo vals val nil |
149 | lua_rawseti( L, fifo_idx, at); // ... fifo vals val | 149 | 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_) | |||
220 | ["debug"] = true, | 220 | ["debug"] = true, |
221 | ["bit32"] = true, -- Lua 5.2 only, ignored silently under 5.1 | 221 | ["bit32"] = true, -- Lua 5.2 only, ignored silently under 5.1 |
222 | ["utf8"] = true, -- Lua 5.3 only, ignored silently under 5.1 and 5.2 | 222 | ["utf8"] = true, -- Lua 5.3 only, ignored silently under 5.1 and 5.2 |
223 | ["bit"] = true, -- LuaJIT only, ignored silently under PUC-Lua | ||
224 | ["jit"] = true, -- LuaJIT only, ignored silently under PUC-Lua | ||
225 | ["ffi"] = true, -- LuaJIT only, ignored silently under PUC-Lua | ||
223 | -- | 226 | -- |
224 | ["base"] = true, | 227 | ["base"] = true, |
225 | ["coroutine"] = true, -- part of "base" in Lua 5.1 | 228 | ["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[] = | |||
206 | { LUA_COLIBNAME, NULL}, // Lua 5.1: part of base package | 206 | { LUA_COLIBNAME, NULL}, // Lua 5.1: part of base package |
207 | #endif // LUA_VERSION_NUM | 207 | #endif // LUA_VERSION_NUM |
208 | { LUA_DBLIBNAME, luaopen_debug}, | 208 | { LUA_DBLIBNAME, luaopen_debug}, |
209 | #if defined LUA_JITLIBNAME // building against LuaJIT headers, add some LuaJIT-specific libs | ||
210 | #pragma message( "supporting JIT base libs") | ||
211 | { LUA_BITLIBNAME, luaopen_bit}, | ||
212 | { LUA_JITLIBNAME, luaopen_jit}, | ||
213 | { LUA_FFILIBNAME, luaopen_ffi}, | ||
214 | #endif // LUA_JITLIBNAME | ||
215 | |||
216 | { LUA_DBLIBNAME, luaopen_debug}, | ||
209 | { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) | 217 | { "lanes.core", require_lanes_core}, // So that we can open it like any base library (possible since we have access to the init function) |
210 | // | 218 | // |
211 | { "base", NULL}, // ignore "base" (already acquired it) | 219 | { "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 | |||
1393 | { | 1401 | { |
1394 | bool_t ret = TRUE; | 1402 | bool_t ret = TRUE; |
1395 | bool_t ignore = FALSE; | 1403 | bool_t ignore = FALSE; |
1404 | int val_type = lua_type(L, i); | ||
1396 | STACK_GROW( L2, 1); | 1405 | STACK_GROW( L2, 1); |
1397 | STACK_CHECK( L2); | 1406 | STACK_CHECK( L2); |
1398 | 1407 | ||
1399 | /* Skip the object if it has metatable with { __lanesignore = true } */ | 1408 | /* Skip the object if it has metatable with { __lanesignore = true } */ |
1400 | if( lua_getmetatable( L, i)) // ... mt | 1409 | if( lua_getmetatable( L, i)) // ... mt |
1401 | { | 1410 | { |
1402 | lua_pushstring( L, "__lanesignore"); // ... mt "__lanesignore" | 1411 | lua_getfield( L, -1, "__lanesignore"); // ... mt ignore? |
1403 | lua_gettable( L, -2); // ... mt ignore? | ||
1404 | |||
1405 | if( lua_isboolean( L, -1) && lua_toboolean( L, -1)) | 1412 | if( lua_isboolean( L, -1) && lua_toboolean( L, -1)) |
1406 | { | 1413 | { |
1407 | ignore = TRUE; | 1414 | val_type = LUA_TNIL; |
1408 | } | 1415 | } |
1409 | |||
1410 | lua_pop( L, 2); // ... | 1416 | lua_pop( L, 2); // ... |
1411 | } | 1417 | } |
1412 | 1418 | ||
1413 | /* Lets push nil to L2 if the object should be ignored */ | 1419 | /* Lets push nil to L2 if the object should be ignored */ |
1414 | switch( ignore ? LUA_TNIL : lua_type( L, i)) | 1420 | switch( val_type) |
1415 | { | 1421 | { |
1416 | /* Basic types allowed both as values, and as table keys */ | 1422 | /* Basic types allowed both as values, and as table keys */ |
1417 | 1423 | ||
@@ -1664,6 +1670,7 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca | |||
1664 | 1670 | ||
1665 | /* The following types cannot be copied */ | 1671 | /* The following types cannot be copied */ |
1666 | 1672 | ||
1673 | case 10: // LuaJIT CDATA | ||
1667 | case LUA_TTHREAD: | 1674 | case LUA_TTHREAD: |
1668 | ret = FALSE; | 1675 | ret = FALSE; |
1669 | break; | 1676 | 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 @@ | |||
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | // For some reason, LuaJIT 64bits doesn't support lua_newstate() | 19 | // For some reason, LuaJIT 64bits doesn't support lua_newstate() |
20 | #if defined(LUA_LJDIR) && (defined(__x86_64__) || defined(_M_X64)) | 20 | #if defined(LUA_JITLIBNAME) && (defined(__x86_64__) || defined(_M_X64)) |
21 | //#pragma message( "LuaJIT 64 bits detected: don't propagate allocf") | ||
21 | #define PROPAGATE_ALLOCF 0 | 22 | #define PROPAGATE_ALLOCF 0 |
22 | #else // LuaJIT x64 | 23 | #else // LuaJIT x64 |
24 | //#pragma message( "PUC-Lua detected: propagate allocf") | ||
23 | #define PROPAGATE_ALLOCF 1 | 25 | #define PROPAGATE_ALLOCF 1 |
24 | #endif // LuaJIT x64 | 26 | #endif // LuaJIT x64 |
25 | #if PROPAGATE_ALLOCF | 27 | #if PROPAGATE_ALLOCF |