diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-18 09:56:44 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-19 15:57:52 +0100 |
commit | 37e9658f74f9421aaae5fe71f12eb2221f2d574a (patch) | |
tree | f55aeab48b2b4edf3267aaf1f5459d52c9b7aa36 /src | |
parent | 352c7bec48f166e34fa94f7481882a8b5958e15c (diff) | |
download | lanes-37e9658f74f9421aaae5fe71f12eb2221f2d574a.tar.gz lanes-37e9658f74f9421aaae5fe71f12eb2221f2d574a.tar.bz2 lanes-37e9658f74f9421aaae5fe71f12eb2221f2d574a.zip |
C++ migration: buildfixes
Essentially, buildfixes when compiling as C++, plus properly marking public API as extern "C"
Diffstat (limited to 'src')
-rw-r--r-- | src/cancel.h | 11 | ||||
-rw-r--r-- | src/compat.h | 11 | ||||
-rw-r--r-- | src/deep.c | 76 | ||||
-rw-r--r-- | src/deep.h | 26 | ||||
-rw-r--r-- | src/keeper.h | 12 | ||||
-rw-r--r-- | src/lanes.c | 8 | ||||
-rw-r--r-- | src/lanes.h | 22 | ||||
-rw-r--r-- | src/lanes_private.h | 20 | ||||
-rw-r--r-- | src/lanesconf.h | 17 | ||||
-rw-r--r-- | src/linda.c | 2 | ||||
-rw-r--r-- | src/macros_and_utils.h | 14 | ||||
-rw-r--r-- | src/platform.h | 5 | ||||
-rw-r--r-- | src/state.c | 2 | ||||
-rw-r--r-- | src/state.h | 6 | ||||
-rw-r--r-- | src/threading.h | 8 | ||||
-rw-r--r-- | src/tools.c | 2 | ||||
-rw-r--r-- | src/tools.h | 6 | ||||
-rw-r--r-- | src/uniquekey.h | 5 | ||||
-rw-r--r-- | src/universe.c | 2 | ||||
-rw-r--r-- | src/universe.h | 15 |
20 files changed, 135 insertions, 135 deletions
diff --git a/src/cancel.h b/src/cancel.h index c7c5433..bd6a1d0 100644 --- a/src/cancel.h +++ b/src/cancel.h | |||
@@ -1,9 +1,14 @@ | |||
1 | #if !defined( __LANES_CANCEL_H__) | 1 | #pragma once |
2 | #define __LANES_CANCEL_H__ 1 | ||
3 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
4 | #include "lua.h" | 6 | #include "lua.h" |
5 | #include "lualib.h" | 7 | #include "lualib.h" |
6 | #include "lauxlib.h" | 8 | #include "lauxlib.h" |
9 | #ifdef __cplusplus | ||
10 | } | ||
11 | #endif // __cplusplus | ||
7 | 12 | ||
8 | #include "uniquekey.h" | 13 | #include "uniquekey.h" |
9 | #include "macros_and_utils.h" | 14 | #include "macros_and_utils.h" |
@@ -62,5 +67,3 @@ LUAG_FUNC( cancel_test); | |||
62 | LUAG_FUNC( thread_cancel); | 67 | LUAG_FUNC( thread_cancel); |
63 | 68 | ||
64 | // ################################################################################################ | 69 | // ################################################################################################ |
65 | |||
66 | #endif // __LANES_CANCEL_H__ | ||
diff --git a/src/compat.h b/src/compat.h index e44f827..ed56cc6 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -1,9 +1,14 @@ | |||
1 | #if !defined( __COMPAT_H__) | 1 | #pragma once |
2 | #define __COMPAT_H__ 1 | ||
3 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
4 | #include "lua.h" | 6 | #include "lua.h" |
5 | #include "lualib.h" | 7 | #include "lualib.h" |
6 | #include "lauxlib.h" | 8 | #include "lauxlib.h" |
9 | #ifdef __cplusplus | ||
10 | } | ||
11 | #endif // __cplusplus | ||
7 | 12 | ||
8 | // try to detect if we are building against LuaJIT or MoonJIT | 13 | // try to detect if we are building against LuaJIT or MoonJIT |
9 | #if defined(LUA_JITLIBNAME) | 14 | #if defined(LUA_JITLIBNAME) |
@@ -92,5 +97,3 @@ int lua_setiuservalue( lua_State* L, int idx, int n); | |||
92 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | 97 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) |
93 | 98 | ||
94 | #endif // LUA_VERSION_NUM == 504 | 99 | #endif // LUA_VERSION_NUM == 504 |
95 | |||
96 | #endif // __COMPAT_H__ | ||
@@ -97,8 +97,8 @@ static void get_deep_lookup( lua_State* L) | |||
97 | REGISTRY_GET( L, DEEP_LOOKUP_KEY); // a {} | 97 | REGISTRY_GET( L, DEEP_LOOKUP_KEY); // a {} |
98 | if( !lua_isnil( L, -1)) | 98 | if( !lua_isnil( L, -1)) |
99 | { | 99 | { |
100 | lua_insert( L, -2); // {} a | 100 | lua_insert( L, -2); // {} a |
101 | lua_rawget( L, -2); // {} b | 101 | lua_rawget( L, -2); // {} b |
102 | } | 102 | } |
103 | lua_remove( L, -2); // a|b | 103 | lua_remove( L, -2); // a|b |
104 | STACK_END( L, 1); | 104 | STACK_END( L, 1); |
@@ -173,7 +173,7 @@ static int deep_userdata_gc( lua_State* L) | |||
173 | if( v == 0) | 173 | if( v == 0) |
174 | { | 174 | { |
175 | // retrieve wrapped __gc | 175 | // retrieve wrapped __gc |
176 | lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? | 176 | lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? |
177 | if( !lua_isnil( L, -1)) | 177 | if( !lua_isnil( L, -1)) |
178 | { | 178 | { |
179 | lua_insert( L, -2); // __gc self | 179 | lua_insert( L, -2); // __gc self |
@@ -213,12 +213,12 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
213 | lua_rawget( L, -2); // DPC proxy | 213 | lua_rawget( L, -2); // DPC proxy |
214 | if ( !lua_isnil( L, -1)) | 214 | if ( !lua_isnil( L, -1)) |
215 | { | 215 | { |
216 | lua_remove( L, -2); // proxy | 216 | lua_remove( L, -2); // proxy |
217 | return NULL; | 217 | return NULL; |
218 | } | 218 | } |
219 | else | 219 | else |
220 | { | 220 | { |
221 | lua_pop( L, 1); // DPC | 221 | lua_pop( L, 1); // DPC |
222 | } | 222 | } |
223 | 223 | ||
224 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 224 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded |
@@ -231,7 +231,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
231 | STACK_CHECK( L, 0); | 231 | STACK_CHECK( L, 0); |
232 | 232 | ||
233 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) | 233 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) |
234 | proxy = lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy | 234 | proxy = (DeepPrelude**) lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy |
235 | ASSERT_L( proxy); | 235 | ASSERT_L( proxy); |
236 | *proxy = prelude; | 236 | *proxy = prelude; |
237 | 237 | ||
@@ -242,101 +242,101 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in | |||
242 | if( lua_isnil( L, -1)) // // No metatable yet. | 242 | if( lua_isnil( L, -1)) // // No metatable yet. |
243 | { | 243 | { |
244 | char const* modname; | 244 | char const* modname; |
245 | int oldtop = lua_gettop( L); // DPC proxy nil | 245 | int oldtop = lua_gettop( L); // DPC proxy nil |
246 | lua_pop( L, 1); // DPC proxy | 246 | lua_pop( L, 1); // DPC proxy |
247 | // 1 - make one and register it | 247 | // 1 - make one and register it |
248 | if( mode_ != eLM_ToKeeper) | 248 | if( mode_ != eLM_ToKeeper) |
249 | { | 249 | { |
250 | (void) prelude->idfunc( L, eDO_metatable); // DPC proxy metatable | 250 | (void) prelude->idfunc( L, eDO_metatable); // DPC proxy metatable |
251 | if( lua_gettop( L) - oldtop != 0 || !lua_istable( L, -1)) | 251 | if( lua_gettop( L) - oldtop != 0 || !lua_istable( L, -1)) |
252 | { | 252 | { |
253 | lua_settop( L, oldtop); // DPC proxy X | 253 | lua_settop( L, oldtop); // DPC proxy X |
254 | lua_pop( L, 3); // | 254 | lua_pop( L, 3); // |
255 | return "Bad idfunc(eOP_metatable): unexpected pushed value"; | 255 | return "Bad idfunc(eOP_metatable): unexpected pushed value"; |
256 | } | 256 | } |
257 | // if the metatable contains a __gc, we will call it from our own | 257 | // if the metatable contains a __gc, we will call it from our own |
258 | lua_getfield( L, -1, "__gc"); // DPC proxy metatable __gc | 258 | lua_getfield( L, -1, "__gc"); // DPC proxy metatable __gc |
259 | } | 259 | } |
260 | else | 260 | else |
261 | { | 261 | { |
262 | // keepers need a minimal metatable that only contains our own __gc | 262 | // keepers need a minimal metatable that only contains our own __gc |
263 | lua_newtable( L); // DPC proxy metatable | 263 | lua_newtable( L); // DPC proxy metatable |
264 | lua_pushnil( L); // DPC proxy metatable nil | 264 | lua_pushnil( L); // DPC proxy metatable nil |
265 | } | 265 | } |
266 | if( lua_isnil( L, -1)) | 266 | if( lua_isnil( L, -1)) |
267 | { | 267 | { |
268 | // Add our own '__gc' method | 268 | // Add our own '__gc' method |
269 | lua_pop( L, 1); // DPC proxy metatable | 269 | lua_pop( L, 1); // DPC proxy metatable |
270 | lua_pushcfunction( L, deep_userdata_gc); // DPC proxy metatable deep_userdata_gc | 270 | lua_pushcfunction( L, deep_userdata_gc); // DPC proxy metatable deep_userdata_gc |
271 | } | 271 | } |
272 | else | 272 | else |
273 | { | 273 | { |
274 | // Add our own '__gc' method wrapping the original | 274 | // Add our own '__gc' method wrapping the original |
275 | lua_pushcclosure( L, deep_userdata_gc, 1); // DPC proxy metatable deep_userdata_gc | 275 | lua_pushcclosure( L, deep_userdata_gc, 1); // DPC proxy metatable deep_userdata_gc |
276 | } | 276 | } |
277 | lua_setfield( L, -2, "__gc"); // DPC proxy metatable | 277 | lua_setfield( L, -2, "__gc"); // DPC proxy metatable |
278 | 278 | ||
279 | // Memorize for later rounds | 279 | // Memorize for later rounds |
280 | lua_pushvalue( L, -1); // DPC proxy metatable metatable | 280 | lua_pushvalue( L, -1); // DPC proxy metatable metatable |
281 | lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc | 281 | lua_pushlightuserdata( L, (void*)(ptrdiff_t)(prelude->idfunc)); // DPC proxy metatable metatable idfunc |
282 | set_deep_lookup( L); // DPC proxy metatable | 282 | set_deep_lookup( L); // DPC proxy metatable |
283 | 283 | ||
284 | // 2 - cause the target state to require the module that exported the idfunc | 284 | // 2 - cause the target state to require the module that exported the idfunc |
285 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc | 285 | // this is needed because we must make sure the shared library is still loaded as long as we hold a pointer on the idfunc |
286 | { | 286 | { |
287 | int oldtop_module = lua_gettop( L); | 287 | int oldtop_module = lua_gettop( L); |
288 | modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable | 288 | modname = (char const*) prelude->idfunc( L, eDO_module); // DPC proxy metatable |
289 | // make sure the function pushed nothing on the stack! | 289 | // make sure the function pushed nothing on the stack! |
290 | if( lua_gettop( L) - oldtop_module != 0) | 290 | if( lua_gettop( L) - oldtop_module != 0) |
291 | { | 291 | { |
292 | lua_pop( L, 3); // | 292 | lua_pop( L, 3); // |
293 | return "Bad idfunc(eOP_module): should not push anything"; | 293 | return "Bad idfunc(eOP_module): should not push anything"; |
294 | } | 294 | } |
295 | } | 295 | } |
296 | if( NULL != modname) // we actually got a module name | 296 | if( NULL != modname) // we actually got a module name |
297 | { | 297 | { |
298 | // L.registry._LOADED exists without having registered the 'package' library. | 298 | // L.registry._LOADED exists without having registered the 'package' library. |
299 | lua_getglobal( L, "require"); // DPC proxy metatable require() | 299 | lua_getglobal( L, "require"); // DPC proxy metatable require() |
300 | // check that the module is already loaded (or being loaded, we are happy either way) | 300 | // check that the module is already loaded (or being loaded, we are happy either way) |
301 | if( lua_isfunction( L, -1)) | 301 | if( lua_isfunction( L, -1)) |
302 | { | 302 | { |
303 | lua_pushstring( L, modname); // DPC proxy metatable require() "module" | 303 | lua_pushstring( L, modname); // DPC proxy metatable require() "module" |
304 | lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED | 304 | lua_getfield( L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); // DPC proxy metatable require() "module" _R._LOADED |
305 | if( lua_istable( L, -1)) | 305 | if( lua_istable( L, -1)) |
306 | { | 306 | { |
307 | bool_t alreadyloaded; | 307 | bool_t alreadyloaded; |
308 | lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" | 308 | lua_pushvalue( L, -2); // DPC proxy metatable require() "module" _R._LOADED "module" |
309 | lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module | 309 | lua_rawget( L, -2); // DPC proxy metatable require() "module" _R._LOADED module |
310 | alreadyloaded = lua_toboolean( L, -1); | 310 | alreadyloaded = lua_toboolean( L, -1); |
311 | if( !alreadyloaded) // not loaded | 311 | if( !alreadyloaded) // not loaded |
312 | { | 312 | { |
313 | int require_result; | 313 | int require_result; |
314 | lua_pop( L, 2); // DPC proxy metatable require() "module" | 314 | lua_pop( L, 2); // DPC proxy metatable require() "module" |
315 | // require "modname" | 315 | // require "modname" |
316 | require_result = lua_pcall( L, 1, 0, 0); // DPC proxy metatable error? | 316 | require_result = lua_pcall( L, 1, 0, 0); // DPC proxy metatable error? |
317 | if( require_result != LUA_OK) | 317 | if( require_result != LUA_OK) |
318 | { | 318 | { |
319 | // failed, return the error message | 319 | // failed, return the error message |
320 | lua_pushfstring( L, "error while requiring '%s' identified by idfunc(eOP_module): ", modname); | 320 | lua_pushfstring( L, "error while requiring '%s' identified by idfunc(eOP_module): ", modname); |
321 | lua_insert( L, -2); // DPC proxy metatable prefix error | 321 | lua_insert( L, -2); // DPC proxy metatable prefix error |
322 | lua_concat( L, 2); // DPC proxy metatable error | 322 | lua_concat( L, 2); // DPC proxy metatable error |
323 | return lua_tostring( L, -1); | 323 | return lua_tostring( L, -1); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | else // already loaded, we are happy | 326 | else // already loaded, we are happy |
327 | { | 327 | { |
328 | lua_pop( L, 4); // DPC proxy metatable | 328 | lua_pop( L, 4); // DPC proxy metatable |
329 | } | 329 | } |
330 | } | 330 | } |
331 | else // no L.registry._LOADED; can this ever happen? | 331 | else // no L.registry._LOADED; can this ever happen? |
332 | { | 332 | { |
333 | lua_pop( L, 6); // | 333 | lua_pop( L, 6); // |
334 | return "unexpected error while requiring a module identified by idfunc(eOP_module)"; | 334 | return "unexpected error while requiring a module identified by idfunc(eOP_module)"; |
335 | } | 335 | } |
336 | } | 336 | } |
337 | else // a module name, but no require() function :-( | 337 | else // a module name, but no require() function :-( |
338 | { | 338 | { |
339 | lua_pop( L, 4); // | 339 | lua_pop( L, 4); // |
340 | return "lanes receiving deep userdata should register the 'package' library"; | 340 | return "lanes receiving deep userdata should register the 'package' library"; |
341 | } | 341 | } |
342 | } | 342 | } |
@@ -386,7 +386,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_) | |||
386 | STACK_CHECK( L, 0); | 386 | STACK_CHECK( L, 0); |
387 | { | 387 | { |
388 | int const oldtop = lua_gettop( L); | 388 | int const oldtop = lua_gettop( L); |
389 | DeepPrelude* prelude = idfunc( L, eDO_new); | 389 | DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); |
390 | if( prelude == NULL) | 390 | if( prelude == NULL) |
391 | { | 391 | { |
392 | return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); | 392 | return luaL_error( L, "idfunc(eDO_new) failed to create deep userdata (out of memory)"); |
@@ -473,7 +473,7 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui | |||
473 | lua_pop( L, 1); // ... u [uv]* | 473 | lua_pop( L, 1); // ... u [uv]* |
474 | STACK_MID( L, nuv); | 474 | STACK_MID( L, nuv); |
475 | 475 | ||
476 | errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u | 476 | errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u |
477 | 477 | ||
478 | // transfer all uservalues of the source in the destination | 478 | // transfer all uservalues of the source in the destination |
479 | { | 479 | { |
@@ -481,7 +481,7 @@ bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, ui | |||
481 | while( nuv) | 481 | while( nuv) |
482 | { | 482 | { |
483 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // u uv | 483 | inter_copy_one( U, L2, L2_cache_i, L, lua_absindex( L, -1), VT_NORMAL, mode_, upName_); // u uv |
484 | lua_pop( L, 1); // ... u [uv]* | 484 | lua_pop( L, 1); // ... u [uv]* |
485 | // this pops the value from the stack | 485 | // this pops the value from the stack |
486 | lua_setiuservalue( L2, clone_i, nuv); // u | 486 | lua_setiuservalue( L2, clone_i, nuv); // u |
487 | -- nuv; | 487 | -- nuv; |
@@ -1,27 +1,25 @@ | |||
1 | #ifndef __LANES_DEEP_H__ | 1 | #pragma once |
2 | #define __LANES_DEEP_H__ 1 | ||
3 | 2 | ||
4 | /* | 3 | /* |
5 | * public 'deep' API to be used by external modules if they want to implement Lanes-aware userdata | 4 | * public 'deep' API to be used by external modules if they want to implement Lanes-aware userdata |
6 | * said modules will have to link against lanes (it is not really possible to separate the 'deep userdata' implementation from the rest of Lanes) | 5 | * said modules will have to link against lanes (it is not really possible to separate the 'deep userdata' implementation from the rest of Lanes) |
7 | */ | 6 | */ |
8 | 7 | ||
8 | #ifdef __cplusplus | ||
9 | extern "C" { | ||
10 | #endif // __cplusplus | ||
9 | #include "lua.h" | 11 | #include "lua.h" |
10 | #include "platform.h" | 12 | #ifdef __cplusplus |
13 | } | ||
14 | #endif // __cplusplus | ||
15 | |||
16 | #include "lanesconf.h" | ||
11 | #include "uniquekey.h" | 17 | #include "uniquekey.h" |
12 | 18 | ||
13 | // forwards | 19 | // forwards |
14 | struct s_Universe; | 20 | struct s_Universe; |
15 | typedef struct s_Universe Universe; | 21 | typedef struct s_Universe Universe; |
16 | 22 | ||
17 | #if !defined LANES_API // when deep is compiled standalone outside Lanes | ||
18 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
19 | #define LANES_API __declspec(dllexport) | ||
20 | #else | ||
21 | #define LANES_API | ||
22 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
23 | #endif // LANES_API | ||
24 | |||
25 | enum eLookupMode | 23 | enum eLookupMode |
26 | { | 24 | { |
27 | eLM_LaneBody, // send the lane body directly from the source to the destination lane | 25 | eLM_LaneBody, // send the lane body directly from the source to the destination lane |
@@ -60,7 +58,5 @@ typedef struct s_DeepPrelude DeepPrelude; | |||
60 | char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, int nuv_, LookupMode mode_); | 58 | char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, int nuv_, LookupMode mode_); |
61 | void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); | 59 | void free_deep_prelude( lua_State* L, DeepPrelude* prelude_); |
62 | 60 | ||
63 | extern LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_); | 61 | LANES_API int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction idfunc, int nuv_); |
64 | extern LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); | 62 | LANES_API void* luaG_todeep( lua_State* L, luaG_IdFunction idfunc, int index); |
65 | |||
66 | #endif // __LANES_DEEP_H__ | ||
diff --git a/src/keeper.h b/src/keeper.h index d30aa36..33118be 100644 --- a/src/keeper.h +++ b/src/keeper.h | |||
@@ -1,7 +1,13 @@ | |||
1 | #if !defined( __keeper_h__) | 1 | #pragma once |
2 | #define __keeper_h__ 1 | ||
3 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
4 | #include "lua.h" | 6 | #include "lua.h" |
7 | #ifdef __cplusplus | ||
8 | } | ||
9 | #endif // __cplusplus | ||
10 | |||
5 | #include "threading.h" | 11 | #include "threading.h" |
6 | #include "uniquekey.h" | 12 | #include "uniquekey.h" |
7 | 13 | ||
@@ -53,5 +59,3 @@ int keepercall_set( lua_State* L); | |||
53 | int keepercall_count( lua_State* L); | 59 | int keepercall_count( lua_State* L); |
54 | 60 | ||
55 | int keeper_call( Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, uint_t starting_index); | 61 | int keeper_call( Universe* U, lua_State* K, keeper_api_t _func, lua_State* L, void* linda, uint_t starting_index); |
56 | |||
57 | #endif // __keeper_h__ \ No newline at end of file | ||
diff --git a/src/lanes.c b/src/lanes.c index 332a1b8..deee90c 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -790,7 +790,7 @@ LUAG_FUNC( set_debug_threadname) | |||
790 | { | 790 | { |
791 | DECLARE_CONST_UNIQUE_KEY( hidden_regkey, LG_set_debug_threadname); | 791 | DECLARE_CONST_UNIQUE_KEY( hidden_regkey, LG_set_debug_threadname); |
792 | // C s_lane structure is a light userdata upvalue | 792 | // C s_lane structure is a light userdata upvalue |
793 | Lane* s = lua_touserdata( L, lua_upvalueindex( 1)); | 793 | Lane* s = (Lane*) lua_touserdata( L, lua_upvalueindex( 1)); |
794 | luaL_checktype( L, -1, LUA_TSTRING); // "name" | 794 | luaL_checktype( L, -1, LUA_TSTRING); // "name" |
795 | lua_settop( L, 1); | 795 | lua_settop( L, 1); |
796 | STACK_CHECK_ABS( L, 1); | 796 | STACK_CHECK_ABS( L, 1); |
@@ -1225,7 +1225,7 @@ LUAG_FUNC( lane_new) | |||
1225 | // 's' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) | 1225 | // 's' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) |
1226 | // | 1226 | // |
1227 | // a Lane full userdata needs a single uservalue | 1227 | // a Lane full userdata needs a single uservalue |
1228 | ud = lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane | 1228 | ud = (Lane**) lua_newuserdatauv( L, sizeof( Lane*), 1); // func libs priority globals package required gc_cb lane |
1229 | { | 1229 | { |
1230 | AllocatorDefinition* const allocD = &U->internal_allocator; | 1230 | AllocatorDefinition* const allocD = &U->internal_allocator; |
1231 | s = *ud = (Lane*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); | 1231 | s = *ud = (Lane*) allocD->allocF(allocD->allocUD, NULL, 0, sizeof(Lane)); |
@@ -2074,7 +2074,7 @@ static void EnableCrashingOnCrashes( void) | |||
2074 | } | 2074 | } |
2075 | #endif // PLATFORM_WIN32 | 2075 | #endif // PLATFORM_WIN32 |
2076 | 2076 | ||
2077 | int LANES_API luaopen_lanes_core( lua_State* L) | 2077 | LANES_API int luaopen_lanes_core( lua_State* L) |
2078 | { | 2078 | { |
2079 | #if defined PLATFORM_WIN32 && !defined NDEBUG | 2079 | #if defined PLATFORM_WIN32 && !defined NDEBUG |
2080 | EnableCrashingOnCrashes(); | 2080 | EnableCrashingOnCrashes(); |
@@ -2129,7 +2129,7 @@ static int default_luaopen_lanes( lua_State* L) | |||
2129 | } | 2129 | } |
2130 | 2130 | ||
2131 | // call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application | 2131 | // call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application |
2132 | void LANES_API luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) | 2132 | LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) |
2133 | { | 2133 | { |
2134 | STACK_CHECK( L, 0); | 2134 | STACK_CHECK( L, 0); |
2135 | // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded | 2135 | // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded |
diff --git a/src/lanes.h b/src/lanes.h index 7e1a2e5..6e05cae 100644 --- a/src/lanes.h +++ b/src/lanes.h | |||
@@ -1,14 +1,14 @@ | |||
1 | #if !defined( __lanes_h__) | 1 | #pragma once |
2 | #define __lanes_h__ 1 | ||
3 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
4 | #include "lua.h" | 6 | #include "lua.h" |
5 | #include "platform.h" | 7 | #ifdef __cplusplus |
8 | } | ||
9 | #endif // __cplusplus | ||
6 | 10 | ||
7 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 11 | #include "lanesconf.h" |
8 | #define LANES_API __declspec(dllexport) | ||
9 | #else | ||
10 | #define LANES_API | ||
11 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
12 | 12 | ||
13 | #define LANES_VERSION_MAJOR 3 | 13 | #define LANES_VERSION_MAJOR 3 |
14 | #define LANES_VERSION_MINOR 16 | 14 | #define LANES_VERSION_MINOR 16 |
@@ -20,9 +20,7 @@ | |||
20 | #define LANES_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>PATCH)))) | 20 | #define LANES_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>PATCH)))) |
21 | #define LANES_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) | 21 | #define LANES_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) |
22 | 22 | ||
23 | extern int LANES_API luaopen_lanes_core( lua_State* L); | 23 | LANES_API int luaopen_lanes_core( lua_State* L); |
24 | 24 | ||
25 | // Call this to work with embedded Lanes instead of calling luaopen_lanes_core() | 25 | // Call this to work with embedded Lanes instead of calling luaopen_lanes_core() |
26 | extern void LANES_API luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes); | 26 | LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes); |
27 | |||
28 | #endif // __lanes_h__ \ No newline at end of file | ||
diff --git a/src/lanes_private.h b/src/lanes_private.h index 6717fe0..67c99f7 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h | |||
@@ -1,10 +1,15 @@ | |||
1 | #if !defined __lanes_private_h__ | 1 | #pragma once |
2 | #define __lanes_private_h__ 1 | ||
3 | 2 | ||
4 | #include "uniquekey.h" | 3 | #include "uniquekey.h" |
5 | #include "cancel.h" | 4 | #include "cancel.h" |
6 | #include "universe.h" | 5 | #include "universe.h" |
7 | 6 | ||
7 | enum ThreadStatus | ||
8 | { | ||
9 | NORMAL, // normal master side state | ||
10 | KILLED // issued an OS kill | ||
11 | }; | ||
12 | |||
8 | // NOTE: values to be changed by either thread, during execution, without | 13 | // NOTE: values to be changed by either thread, during execution, without |
9 | // locking, are marked "volatile" | 14 | // locking, are marked "volatile" |
10 | // | 15 | // |
@@ -49,11 +54,7 @@ struct s_Lane | |||
49 | // lane status changes to DONE/ERROR_ST/CANCELLED. | 54 | // lane status changes to DONE/ERROR_ST/CANCELLED. |
50 | #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR | 55 | #endif // THREADWAIT_METHOD == THREADWAIT_CONDVAR |
51 | 56 | ||
52 | volatile enum | 57 | volatile enum ThreadStatus mstatus; |
53 | { | ||
54 | NORMAL, // normal master side state | ||
55 | KILLED // issued an OS kill | ||
56 | } mstatus; | ||
57 | // | 58 | // |
58 | // M: sets to NORMAL, if issued a kill changes to KILLED | 59 | // M: sets to NORMAL, if issued a kill changes to KILLED |
59 | // S: not used | 60 | // S: not used |
@@ -84,13 +85,10 @@ static inline Lane* get_lane_from_registry( lua_State* L) | |||
84 | STACK_GROW( L, 1); | 85 | STACK_GROW( L, 1); |
85 | STACK_CHECK( L, 0); | 86 | STACK_CHECK( L, 0); |
86 | REGISTRY_GET( L, CANCEL_TEST_KEY); | 87 | REGISTRY_GET( L, CANCEL_TEST_KEY); |
87 | s = lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil | 88 | s = (Lane*) lua_touserdata( L, -1); // lightuserdata (true 's_lane' pointer) / nil |
88 | lua_pop( L, 1); | 89 | lua_pop( L, 1); |
89 | STACK_END( L, 0); | 90 | STACK_END( L, 0); |
90 | return s; | 91 | return s; |
91 | } | 92 | } |
92 | 93 | ||
93 | int push_thread_status( lua_State* L, Lane* s); | 94 | int push_thread_status( lua_State* L, Lane* s); |
94 | |||
95 | |||
96 | #endif // __lanes_private_h__ \ No newline at end of file | ||
diff --git a/src/lanesconf.h b/src/lanesconf.h new file mode 100644 index 0000000..fb4a601 --- /dev/null +++ b/src/lanesconf.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "platform.h" | ||
4 | |||
5 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
6 | #ifdef __cplusplus | ||
7 | #define LANES_API extern "C" __declspec(dllexport) | ||
8 | #else | ||
9 | #define LANES_API extern __declspec(dllexport) | ||
10 | #endif // __cplusplus | ||
11 | #else | ||
12 | #ifdef __cplusplus | ||
13 | #define LANES_API extern "C" | ||
14 | #else | ||
15 | #define LANES_API extern | ||
16 | #endif // __cplusplus | ||
17 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | ||
diff --git a/src/linda.c b/src/linda.c index 8b59790..eac6458 100644 --- a/src/linda.c +++ b/src/linda.c | |||
@@ -816,7 +816,7 @@ static void* linda_id( lua_State* L, DeepOp op_) | |||
816 | case eDO_delete: | 816 | case eDO_delete: |
817 | { | 817 | { |
818 | Keeper* K; | 818 | Keeper* K; |
819 | struct s_Linda* linda = lua_touserdata( L, 1); | 819 | struct s_Linda* linda = (struct s_Linda*) lua_touserdata( L, 1); |
820 | ASSERT_L( linda); | 820 | ASSERT_L( linda); |
821 | 821 | ||
822 | // Clean associated structures in the keeper state. | 822 | // Clean associated structures in the keeper state. |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 05a46b5..726fe64 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -1,11 +1,13 @@ | |||
1 | /* | 1 | #pragma once |
2 | * MACROS_AND_UTILS.H | ||
3 | */ | ||
4 | #ifndef MACROS_AND_UTILS_H | ||
5 | #define MACROS_AND_UTILS_H | ||
6 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
7 | #include "lua.h" | 6 | #include "lua.h" |
8 | #include "lualib.h" | 7 | #include "lualib.h" |
8 | #ifdef __cplusplus | ||
9 | } | ||
10 | #endif // __cplusplus | ||
9 | 11 | ||
10 | // M$ compiler doesn't support 'inline' keyword in C files... | 12 | // M$ compiler doesn't support 'inline' keyword in C files... |
11 | #if defined( _MSC_VER) | 13 | #if defined( _MSC_VER) |
@@ -98,5 +100,3 @@ extern char const* debugspew_indent; | |||
98 | } | 100 | } |
99 | 101 | ||
100 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) | 102 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) |
101 | |||
102 | #endif // MACROS_AND_UTILS_H | ||
diff --git a/src/platform.h b/src/platform.h index da5264e..ce621d9 100644 --- a/src/platform.h +++ b/src/platform.h | |||
@@ -1,5 +1,4 @@ | |||
1 | #ifndef __LANES_PLATFORM_H__ | 1 | #pragma once |
2 | #define __LANES_PLATFORM_H__ 1 | ||
3 | 2 | ||
4 | #ifdef _WIN32_WCE | 3 | #ifdef _WIN32_WCE |
5 | #define PLATFORM_POCKETPC | 4 | #define PLATFORM_POCKETPC |
@@ -20,5 +19,3 @@ | |||
20 | #else | 19 | #else |
21 | #error "Unknown platform!" | 20 | #error "Unknown platform!" |
22 | #endif | 21 | #endif |
23 | |||
24 | #endif // __LANES_PLATFORM_H__ | ||
diff --git a/src/state.c b/src/state.c index 21ca397..85ad31e 100644 --- a/src/state.c +++ b/src/state.c | |||
@@ -259,7 +259,7 @@ lua_State* create_state( Universe* U, lua_State* from_) | |||
259 | lua_pushcclosure( from_, U->provide_allocator, 0); | 259 | lua_pushcclosure( from_, U->provide_allocator, 0); |
260 | lua_call( from_, 0, 1); | 260 | lua_call( from_, 0, 1); |
261 | { | 261 | { |
262 | AllocatorDefinition* const def = lua_touserdata( from_, -1); | 262 | AllocatorDefinition* const def = (AllocatorDefinition*) lua_touserdata( from_, -1); |
263 | L = lua_newstate( def->allocF, def->allocUD); | 263 | L = lua_newstate( def->allocF, def->allocUD); |
264 | } | 264 | } |
265 | lua_pop( from_, 1); | 265 | lua_pop( from_, 1); |
diff --git a/src/state.h b/src/state.h index e844405..0ffab02 100644 --- a/src/state.h +++ b/src/state.h | |||
@@ -1,7 +1,5 @@ | |||
1 | #ifndef __LANES_STATE_H__ | 1 | #pragma once |
2 | #define __LANES_STATE_H__ | ||
3 | 2 | ||
4 | //#include "lauxlib.h" | ||
5 | #include "threading.h" | 3 | #include "threading.h" |
6 | #include "deep.h" | 4 | #include "deep.h" |
7 | 5 | ||
@@ -18,5 +16,3 @@ lua_State* luaG_newstate( Universe* U, lua_State* _from, char const* libs); | |||
18 | 16 | ||
19 | void initialize_on_state_create( Universe* U, lua_State* L); | 17 | void initialize_on_state_create( Universe* U, lua_State* L); |
20 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); | 18 | void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, LookupMode mode_); |
21 | |||
22 | #endif // __LANES_STATE_H__ | ||
diff --git a/src/threading.h b/src/threading.h index b1706ac..8324bdd 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -1,8 +1,4 @@ | |||
1 | /* | 1 | #pragma once |
2 | * THREADING.H | ||
3 | */ | ||
4 | #ifndef __threading_h__ | ||
5 | #define __threading_h__ 1 | ||
6 | 2 | ||
7 | /* | 3 | /* |
8 | * win32-pthread: | 4 | * win32-pthread: |
@@ -261,5 +257,3 @@ void THREAD_SETNAME( char const* _name); | |||
261 | void THREAD_MAKE_ASYNCH_CANCELLABLE(); | 257 | void THREAD_MAKE_ASYNCH_CANCELLABLE(); |
262 | void THREAD_SET_PRIORITY( int prio); | 258 | void THREAD_SET_PRIORITY( int prio); |
263 | void THREAD_SET_AFFINITY( unsigned int aff); | 259 | void THREAD_SET_AFFINITY( unsigned int aff); |
264 | |||
265 | #endif // __threading_h__ | ||
diff --git a/src/tools.c b/src/tools.c index 80e0f71..6f4a06a 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -183,7 +183,7 @@ static void* protected_lua_Alloc( void *ud, void *ptr, size_t osize, size_t nsiz | |||
183 | static int luaG_provide_protected_allocator( lua_State* L) | 183 | static int luaG_provide_protected_allocator( lua_State* L) |
184 | { | 184 | { |
185 | Universe* U = universe_get( L); | 185 | Universe* U = universe_get( L); |
186 | AllocatorDefinition* const def = lua_newuserdatauv( L, sizeof(AllocatorDefinition), 0); | 186 | AllocatorDefinition* const def = (AllocatorDefinition*) lua_newuserdatauv( L, sizeof(AllocatorDefinition), 0); |
187 | def->allocF = protected_lua_Alloc; | 187 | def->allocF = protected_lua_Alloc; |
188 | def->allocUD = &U->protected_allocator; | 188 | def->allocUD = &U->protected_allocator; |
189 | return 1; | 189 | return 1; |
diff --git a/src/tools.h b/src/tools.h index a0893e4..c714837 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -1,7 +1,5 @@ | |||
1 | #ifndef __LANES_TOOLS_H__ | 1 | #pragma once |
2 | #define __LANES_TOOLS_H__ | ||
3 | 2 | ||
4 | //#include "lauxlib.h" | ||
5 | #include "threading.h" | 3 | #include "threading.h" |
6 | #include "deep.h" | 4 | #include "deep.h" |
7 | 5 | ||
@@ -53,5 +51,3 @@ static DECLARE_CONST_UNIQUE_KEY( CONFIG_REGKEY, 0x31cd24894eae8624); // 'cancel_ | |||
53 | 51 | ||
54 | // crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/ | 52 | // crc64/we of string "LOOKUP_REGKEY" generated at http://www.nitrxgen.net/hashgen/ |
55 | static DECLARE_CONST_UNIQUE_KEY( LOOKUP_REGKEY, 0x5051ed67ee7b51a1); // 'cancel_error' sentinel | 53 | static DECLARE_CONST_UNIQUE_KEY( LOOKUP_REGKEY, 0x5051ed67ee7b51a1); // 'cancel_error' sentinel |
56 | |||
57 | #endif // __LANES_TOOLS_H__ | ||
diff --git a/src/uniquekey.h b/src/uniquekey.h index 015fbf2..f219ab1 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h | |||
@@ -1,5 +1,4 @@ | |||
1 | #if !defined __LANES_UNIQUEKEY_H__ | 1 | #pragma once |
2 | #define __LANES_UNIQUEKEY_H__ 1 | ||
3 | 2 | ||
4 | #include "compat.h" | 3 | #include "compat.h" |
5 | 4 | ||
@@ -21,5 +20,3 @@ typedef struct s_UniqueKey UniqueKey; | |||
21 | 20 | ||
22 | #define push_unique_key( L, key_) lua_pushlightuserdata( L, key_.value) | 21 | #define push_unique_key( L, key_) lua_pushlightuserdata( L, key_.value) |
23 | #define equal_unique_key( L, i, key_) (lua_touserdata( L, i) == key_.value) | 22 | #define equal_unique_key( L, i, key_) (lua_touserdata( L, i) == key_.value) |
24 | |||
25 | #endif // __LANES_UNIQUEKEY_H__ | ||
diff --git a/src/universe.c b/src/universe.c index 9f84baf..0a014f7 100644 --- a/src/universe.c +++ b/src/universe.c | |||
@@ -68,7 +68,7 @@ Universe* universe_get( lua_State* L) | |||
68 | STACK_GROW( L, 2); | 68 | STACK_GROW( L, 2); |
69 | STACK_CHECK( L, 0); | 69 | STACK_CHECK( L, 0); |
70 | REGISTRY_GET( L, UNIVERSE_REGKEY); | 70 | REGISTRY_GET( L, UNIVERSE_REGKEY); |
71 | universe = lua_touserdata( L, -1); // NULL if nil | 71 | universe = (Universe*) lua_touserdata( L, -1); // NULL if nil |
72 | lua_pop( L, 1); | 72 | lua_pop( L, 1); |
73 | STACK_END( L, 0); | 73 | STACK_END( L, 0); |
74 | return universe; | 74 | return universe; |
diff --git a/src/universe.h b/src/universe.h index 03c78cf..0224e99 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -1,10 +1,13 @@ | |||
1 | /* | 1 | #pragma once |
2 | * UNIVERSE.H | ||
3 | */ | ||
4 | #ifndef UNIVERSE_H | ||
5 | #define UNIVERSE_H | ||
6 | 2 | ||
3 | #ifdef __cplusplus | ||
4 | extern "C" { | ||
5 | #endif // __cplusplus | ||
7 | #include "lua.h" | 6 | #include "lua.h" |
7 | #ifdef __cplusplus | ||
8 | } | ||
9 | #endif // __cplusplus | ||
10 | |||
8 | #include "threading.h" | 11 | #include "threading.h" |
9 | #include "macros_and_utils.h" | 12 | #include "macros_and_utils.h" |
10 | 13 | ||
@@ -101,5 +104,3 @@ typedef struct s_Universe Universe; | |||
101 | Universe* universe_get( lua_State* L); | 104 | Universe* universe_get( lua_State* L); |
102 | Universe* universe_create( lua_State* L); | 105 | Universe* universe_create( lua_State* L); |
103 | void universe_store( lua_State* L, Universe* U); | 106 | void universe_store( lua_State* L, Universe* U); |
104 | |||
105 | #endif // UNIVERSE_H | ||