diff options
-rw-r--r-- | deep_test/deep_test.cpp | 4 | ||||
-rw-r--r-- | src/cancel.h | 5 | ||||
-rw-r--r-- | src/compat.h | 42 | ||||
-rw-r--r-- | src/deep.h | 17 | ||||
-rw-r--r-- | src/keeper.h | 3 | ||||
-rw-r--r-- | src/lanes.h | 13 | ||||
-rw-r--r-- | src/lanes_private.h | 3 | ||||
-rw-r--r-- | src/linda.h | 12 | ||||
-rw-r--r-- | src/lindafactory.h | 6 | ||||
-rw-r--r-- | src/macros_and_utils.h | 88 | ||||
-rw-r--r-- | src/platform.h | 20 | ||||
-rw-r--r-- | src/threading.h | 6 | ||||
-rw-r--r-- | src/tools.h | 3 | ||||
-rw-r--r-- | src/uniquekey.h | 14 | ||||
-rw-r--r-- | src/universe.h | 21 |
15 files changed, 126 insertions, 131 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp index 77ecefb..35a2e56 100644 --- a/deep_test/deep_test.cpp +++ b/deep_test/deep_test.cpp | |||
@@ -13,13 +13,13 @@ class MyDeepFactory : public DeepFactory | |||
13 | 13 | ||
14 | private: | 14 | private: |
15 | 15 | ||
16 | DeepPrelude* newDeepObjectInternal(lua_State* L) const override; | 16 | [[nodiscard]] DeepPrelude* newDeepObjectInternal(lua_State* L) const override; |
17 | void deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const override; | 17 | void deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const override; |
18 | void createMetatable(lua_State* L_) const override | 18 | void createMetatable(lua_State* L_) const override |
19 | { | 19 | { |
20 | luaL_getmetatable(L_, "deep"); | 20 | luaL_getmetatable(L_, "deep"); |
21 | } | 21 | } |
22 | char const* moduleName() const override { return "deep_test"; } | 22 | [[nodiscard]] char const* moduleName() const override { return "deep_test"; } |
23 | }; | 23 | }; |
24 | /*static*/ MyDeepFactory MyDeepFactory::Instance{}; | 24 | /*static*/ MyDeepFactory MyDeepFactory::Instance{}; |
25 | 25 | ||
diff --git a/src/cancel.h b/src/cancel.h index bbc7787..8c8063f 100644 --- a/src/cancel.h +++ b/src/cancel.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #include "lualib.h" | 8 | #include "lualib.h" |
@@ -24,7 +25,7 @@ enum class CancelRequest | |||
24 | { | 25 | { |
25 | None, // no pending cancel request | 26 | None, // no pending cancel request |
26 | Soft, // user wants the lane to cancel itself manually on cancel_test() | 27 | Soft, // user wants the lane to cancel itself manually on cancel_test() |
27 | Hard // user wants the lane to be interrupted (meaning code won't return from those functions) from inside linda:send/receive calls | 28 | Hard // user wants the lane to be interrupted (meaning code won't return from those functions) from inside linda:send/receive calls |
28 | }; | 29 | }; |
29 | 30 | ||
30 | enum class CancelResult | 31 | enum class CancelResult |
diff --git a/src/compat.h b/src/compat.h index 8d10e78..037a3ba 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #include "lualib.h" | 8 | #include "lualib.h" |
@@ -22,16 +23,15 @@ extern "C" { | |||
22 | #define LUAJIT_FLAVOR() 0 | 23 | #define LUAJIT_FLAVOR() 0 |
23 | #endif // LUA_JITLIBNAME | 24 | #endif // LUA_JITLIBNAME |
24 | 25 | ||
25 | |||
26 | // code is now preferring Lua 5.4 API | 26 | // code is now preferring Lua 5.4 API |
27 | 27 | ||
28 | // add some Lua 5.3-style API when building for Lua 5.1 | 28 | // add some Lua 5.3-style API when building for Lua 5.1 |
29 | #if LUA_VERSION_NUM == 501 | 29 | #if LUA_VERSION_NUM == 501 |
30 | 30 | ||
31 | #define lua501_equal lua_equal | 31 | #define lua501_equal lua_equal |
32 | #define lua_absindex( L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) +1) | 32 | #define lua_absindex(L, idx) (((idx) >= 0 || (idx) <= LUA_REGISTRYINDEX) ? (idx) : lua_gettop(L) + (idx) + 1) |
33 | #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap | 33 | #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap |
34 | #define lua_pushglobaltable(L) lua_pushvalue( L, LUA_GLOBALSINDEX) | 34 | #define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) |
35 | #endif // LUAJIT_VERSION_NUM | 35 | #endif // LUAJIT_VERSION_NUM |
36 | #define lua_setuservalue lua_setfenv | 36 | #define lua_setuservalue lua_setfenv |
37 | #define lua_getuservalue lua_getfenv | 37 | #define lua_getuservalue lua_getfenv |
@@ -39,8 +39,8 @@ extern "C" { | |||
39 | #define luaG_registerlibfuncs(L, _funcs) luaL_register(L, nullptr, _funcs) | 39 | #define luaG_registerlibfuncs(L, _funcs) luaL_register(L, nullptr, _funcs) |
40 | #define LUA_OK 0 | 40 | #define LUA_OK 0 |
41 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value | 41 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value |
42 | void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources | 42 | void luaL_requiref(lua_State* L, const char* modname, lua_CFunction openf, int glb); // implementation copied from Lua 5.2 sources |
43 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) | 43 | #define lua504_dump(L, writer, data, strip) lua_dump(L, writer, data) |
44 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 | 44 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 |
45 | 45 | ||
46 | #endif // LUA_VERSION_NUM == 501 | 46 | #endif // LUA_VERSION_NUM == 501 |
@@ -49,13 +49,13 @@ void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int | |||
49 | #if LUA_VERSION_NUM == 502 | 49 | #if LUA_VERSION_NUM == 502 |
50 | 50 | ||
51 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 51 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
52 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 52 | #define lua501_equal(L, a, b) lua_compare(L, a, b, LUA_OPEQ) |
53 | #endif // lua501_equal | 53 | #endif // lua501_equal |
54 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h | 54 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h |
55 | #define lua_lessthan( L, a, b) lua_compare( L, a, b, LUA_OPLT) | 55 | #define lua_lessthan(L, a, b) lua_compare(L, a, b, LUA_OPLT) |
56 | #endif // lua_lessthan | 56 | #endif // lua_lessthan |
57 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 57 | #define luaG_registerlibfuncs(L, _funcs) luaL_setfuncs(L, _funcs, 0) |
58 | #define lua504_dump( L, writer, data, strip) lua_dump( L, writer, data) | 58 | #define lua504_dump(L, writer, data, strip) lua_dump(L, writer, data) |
59 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 | 59 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 |
60 | 60 | ||
61 | #endif // LUA_VERSION_NUM == 502 | 61 | #endif // LUA_VERSION_NUM == 502 |
@@ -64,22 +64,22 @@ void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int | |||
64 | #if LUA_VERSION_NUM == 503 | 64 | #if LUA_VERSION_NUM == 503 |
65 | 65 | ||
66 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 66 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
67 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 67 | #define lua501_equal(L, a, b) lua_compare(L, a, b, LUA_OPEQ) |
68 | #endif // lua501_equal | 68 | #endif // lua501_equal |
69 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h | 69 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h |
70 | #define lua_lessthan( L, a, b) lua_compare( L, a, b, LUA_OPLT) | 70 | #define lua_lessthan(L, a, b) lua_compare(L, a, b, LUA_OPLT) |
71 | #endif // lua_lessthan | 71 | #endif // lua_lessthan |
72 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 72 | #define luaG_registerlibfuncs(L, _funcs) luaL_setfuncs(L, _funcs, 0) |
73 | #define lua504_dump lua_dump | 73 | #define lua504_dump lua_dump |
74 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | 74 | #define luaL_optint(L, n, d) ((int) luaL_optinteger(L, (n), (d))) |
75 | 75 | ||
76 | #endif // LUA_VERSION_NUM == 503 | 76 | #endif // LUA_VERSION_NUM == 503 |
77 | 77 | ||
78 | #if LUA_VERSION_NUM < 504 | 78 | #if LUA_VERSION_NUM < 504 |
79 | 79 | ||
80 | void *lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue); | 80 | void* lua_newuserdatauv(lua_State* L, size_t sz, int nuvalue); |
81 | int lua_getiuservalue( lua_State* L, int idx, int n); | 81 | int lua_getiuservalue(lua_State* L, int idx, int n); |
82 | int lua_setiuservalue( lua_State* L, int idx, int n); | 82 | int lua_setiuservalue(lua_State* L, int idx, int n); |
83 | 83 | ||
84 | #endif // LUA_VERSION_NUM < 504 | 84 | #endif // LUA_VERSION_NUM < 504 |
85 | 85 | ||
@@ -87,14 +87,14 @@ int lua_setiuservalue( lua_State* L, int idx, int n); | |||
87 | #if LUA_VERSION_NUM == 504 | 87 | #if LUA_VERSION_NUM == 504 |
88 | 88 | ||
89 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h | 89 | #ifndef lua501_equal // already defined when compatibility is active in luaconf.h |
90 | #define lua501_equal( L, a, b) lua_compare( L, a, b, LUA_OPEQ) | 90 | #define lua501_equal(L, a, b) lua_compare(L, a, b, LUA_OPEQ) |
91 | #endif // lua501_equal | 91 | #endif // lua501_equal |
92 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h | 92 | #ifndef lua_lessthan // already defined when compatibility is active in luaconf.h |
93 | #define lua_lessthan( L, a, b) lua_compare( L, a, b, LUA_OPLT) | 93 | #define lua_lessthan(L, a, b) lua_compare(L, a, b, LUA_OPLT) |
94 | #endif // lua_lessthan | 94 | #endif // lua_lessthan |
95 | #define luaG_registerlibfuncs( L, _funcs) luaL_setfuncs( L, _funcs, 0) | 95 | #define luaG_registerlibfuncs(L, _funcs) luaL_setfuncs(L, _funcs, 0) |
96 | #define lua504_dump lua_dump | 96 | #define lua504_dump lua_dump |
97 | #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))) |
98 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.4, we don't care about the actual value | 98 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.4, we don't care about the actual value |
99 | 99 | ||
100 | #endif // LUA_VERSION_NUM == 504 | 100 | #endif // LUA_VERSION_NUM == 504 |
@@ -6,7 +6,8 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifdef __cplusplus | 8 | #ifdef __cplusplus |
9 | extern "C" { | 9 | extern "C" |
10 | { | ||
10 | #endif // __cplusplus | 11 | #endif // __cplusplus |
11 | #include "lua.h" | 12 | #include "lua.h" |
12 | #ifdef __cplusplus | 13 | #ifdef __cplusplus |
@@ -53,13 +54,11 @@ struct DeepPrelude | |||
53 | class DeepFactory | 54 | class DeepFactory |
54 | { | 55 | { |
55 | protected: | 56 | protected: |
56 | |||
57 | // protected non-virtual destructor: Lanes won't manage the Factory's lifetime | 57 | // protected non-virtual destructor: Lanes won't manage the Factory's lifetime |
58 | DeepFactory() = default; | 58 | DeepFactory() = default; |
59 | ~DeepFactory() = default; | 59 | ~DeepFactory() = default; |
60 | 60 | ||
61 | public: | 61 | public: |
62 | |||
63 | // non-copyable, non-movable | 62 | // non-copyable, non-movable |
64 | DeepFactory(DeepFactory const&) = delete; | 63 | DeepFactory(DeepFactory const&) = delete; |
65 | DeepFactory(DeepFactory const&&) = delete; | 64 | DeepFactory(DeepFactory const&&) = delete; |
@@ -67,18 +66,16 @@ class DeepFactory | |||
67 | DeepFactory& operator=(DeepFactory const&&) = delete; | 66 | DeepFactory& operator=(DeepFactory const&&) = delete; |
68 | 67 | ||
69 | private: | 68 | private: |
70 | |||
71 | // NVI: private overrides | 69 | // NVI: private overrides |
72 | virtual DeepPrelude* newDeepObjectInternal(lua_State* L_) const = 0; | 70 | [[nodiscard]] virtual DeepPrelude* newDeepObjectInternal(lua_State* L_) const = 0; |
73 | virtual void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const = 0; | 71 | virtual void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const = 0; |
74 | virtual void createMetatable(lua_State* L_) const = 0; | 72 | virtual void createMetatable(lua_State* L_) const = 0; |
75 | virtual char const* moduleName() const = 0; | 73 | [[nodiscard]] virtual char const* moduleName() const = 0; |
76 | 74 | ||
77 | public: | 75 | public: |
78 | |||
79 | // NVI: public interface | 76 | // NVI: public interface |
80 | int pushDeepUserdata(DestState L_, int nuv_) const; | 77 | [[nodiscard]] int pushDeepUserdata(DestState L_, int nuv_) const; |
81 | DeepPrelude* toDeep(lua_State* L_, int index_) const; | 78 | [[nodiscard]] DeepPrelude* toDeep(lua_State* L_, int index_) const; |
82 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); | 79 | static void DeleteDeepObject(lua_State* L_, DeepPrelude* o_); |
83 | static char const* PushDeepProxy(DestState L_, DeepPrelude* o_, int nuv_, LookupMode mode_); | 80 | [[nodiscard]] static char const* PushDeepProxy(DestState L_, DeepPrelude* o_, int nuv_, LookupMode mode_); |
84 | }; | 81 | }; |
diff --git a/src/keeper.h b/src/keeper.h index 27a4cff..6688fe0 100644 --- a/src/keeper.h +++ b/src/keeper.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #ifdef __cplusplus | 8 | #ifdef __cplusplus |
diff --git a/src/lanes.h b/src/lanes.h index 6f8a084..287e405 100644 --- a/src/lanes.h +++ b/src/lanes.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #ifdef __cplusplus | 8 | #ifdef __cplusplus |
@@ -16,11 +17,11 @@ extern "C" { | |||
16 | #define LANES_VERSION_MINOR 0 | 17 | #define LANES_VERSION_MINOR 0 |
17 | #define LANES_VERSION_PATCH 0 | 18 | #define LANES_VERSION_PATCH 0 |
18 | 19 | ||
19 | #define LANES_MIN_VERSION_REQUIRED(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_MIN_VERSION_REQUIRED(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_LESS_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_LESS_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_LESS_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 | #define LANES_VERSION_LESS_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 | #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)))) | 23 | #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)))) |
23 | #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)))) | 24 | #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)))) |
24 | 25 | ||
25 | LANES_API [[nodiscard]] int luaopen_lanes_core(lua_State* L); | 26 | LANES_API [[nodiscard]] int luaopen_lanes_core(lua_State* L); |
26 | 27 | ||
diff --git a/src/lanes_private.h b/src/lanes_private.h index 7ecb9a7..859c8a2 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h | |||
@@ -16,7 +16,6 @@ | |||
16 | class Lane | 16 | class Lane |
17 | { | 17 | { |
18 | public: | 18 | public: |
19 | |||
20 | /* | 19 | /* |
21 | Pending: The Lua VM hasn't done anything yet. | 20 | Pending: The Lua VM hasn't done anything yet. |
22 | Running, Waiting: Thread is inside the Lua VM. If the thread is forcefully stopped, we can't lua_close() the Lua State. | 21 | Running, Waiting: Thread is inside the Lua VM. If the thread is forcefully stopped, we can't lua_close() the Lua State. |
@@ -53,7 +52,7 @@ class Lane | |||
53 | // S: while S is running, M must keep out of modifying the state | 52 | // S: while S is running, M must keep out of modifying the state |
54 | 53 | ||
55 | Status volatile m_status{ Pending }; | 54 | Status volatile m_status{ Pending }; |
56 | // | 55 | // |
57 | // M: sets to Pending (before launching) | 56 | // M: sets to Pending (before launching) |
58 | // S: updates -> Running/Waiting -> Done/Error/Cancelled | 57 | // S: updates -> Running/Waiting -> Done/Error/Cancelled |
59 | 58 | ||
diff --git a/src/linda.h b/src/linda.h index 21b6ecc..dbf48b3 100644 --- a/src/linda.h +++ b/src/linda.h | |||
@@ -20,10 +20,10 @@ static constexpr UniqueKey kLindaBatched{ 0xB8234DF772646567ull, "linda.batched" | |||
20 | 20 | ||
21 | using LindaGroup = Unique<int>; | 21 | using LindaGroup = Unique<int>; |
22 | 22 | ||
23 | class Linda : public DeepPrelude // Deep userdata MUST start with this header | 23 | class Linda |
24 | : public DeepPrelude // Deep userdata MUST start with this header | ||
24 | { | 25 | { |
25 | private: | 26 | private: |
26 | |||
27 | static constexpr size_t kEmbeddedNameLength = 24; | 27 | static constexpr size_t kEmbeddedNameLength = 24; |
28 | using EmbeddedName = std::array<char, kEmbeddedNameLength>; | 28 | using EmbeddedName = std::array<char, kEmbeddedNameLength>; |
29 | struct AllocatedName | 29 | struct AllocatedName |
@@ -35,7 +35,6 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header | |||
35 | std::variant<AllocatedName, EmbeddedName> m_name; | 35 | std::variant<AllocatedName, EmbeddedName> m_name; |
36 | 36 | ||
37 | public: | 37 | public: |
38 | |||
39 | std::condition_variable m_read_happened; | 38 | std::condition_variable m_read_happened; |
40 | std::condition_variable m_write_happened; | 39 | std::condition_variable m_write_happened; |
41 | Universe* const U{ nullptr }; // the universe this linda belongs to | 40 | Universe* const U{ nullptr }; // the universe this linda belongs to |
@@ -43,7 +42,6 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header | |||
43 | CancelRequest simulate_cancel{ CancelRequest::None }; | 42 | CancelRequest simulate_cancel{ CancelRequest::None }; |
44 | 43 | ||
45 | public: | 44 | public: |
46 | |||
47 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents | 45 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents |
48 | [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); } | 46 | [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internal_allocator.alloc(size_); } |
49 | // always embedded somewhere else or "in-place constructed" as a full userdata | 47 | // always embedded somewhere else or "in-place constructed" as a full userdata |
@@ -61,14 +59,12 @@ class Linda : public DeepPrelude // Deep userdata MUST start with this header | |||
61 | Linda& operator=(Linda const&) = delete; | 59 | Linda& operator=(Linda const&) = delete; |
62 | Linda& operator=(Linda const&&) = delete; | 60 | Linda& operator=(Linda const&&) = delete; |
63 | 61 | ||
64 | static int ProtectedCall(lua_State* L, lua_CFunction f_); | 62 | [[nodiscard]] static int ProtectedCall(lua_State* L, lua_CFunction f_); |
65 | |||
66 | private : | ||
67 | 63 | ||
64 | private: | ||
68 | void setName(char const* name_, size_t len_); | 65 | void setName(char const* name_, size_t len_); |
69 | 66 | ||
70 | public: | 67 | public: |
71 | |||
72 | [[nodiscard]] char const* getName() const; | 68 | [[nodiscard]] char const* getName() const; |
73 | [[nodiscard]] Keeper* whichKeeper() const { return U->keepers->nb_keepers ? &U->keepers->keeper_array[m_keeper_index] : nullptr; } | 69 | [[nodiscard]] Keeper* whichKeeper() const { return U->keepers->nb_keepers ? &U->keepers->keeper_array[m_keeper_index] : nullptr; } |
74 | [[nodiscard]] Keeper* acquireKeeper() const; | 70 | [[nodiscard]] Keeper* acquireKeeper() const; |
diff --git a/src/lindafactory.h b/src/lindafactory.h index d31af1f..271f9a7 100644 --- a/src/lindafactory.h +++ b/src/lindafactory.h | |||
@@ -8,7 +8,6 @@ class LindaFactory | |||
8 | : public DeepFactory | 8 | : public DeepFactory |
9 | { | 9 | { |
10 | public: | 10 | public: |
11 | |||
12 | // I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? | 11 | // I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? |
13 | static LindaFactory Instance; | 12 | static LindaFactory Instance; |
14 | 13 | ||
@@ -18,11 +17,10 @@ class LindaFactory | |||
18 | } | 17 | } |
19 | 18 | ||
20 | private: | 19 | private: |
21 | |||
22 | luaL_Reg const* const mLindaMT{ nullptr }; | 20 | luaL_Reg const* const mLindaMT{ nullptr }; |
23 | 21 | ||
24 | void createMetatable(lua_State* L_) const override; | 22 | void createMetatable(lua_State* L_) const override; |
25 | void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const override; | 23 | void deleteDeepObjectInternal(lua_State* L_, DeepPrelude* o_) const override; |
26 | char const* moduleName() const override; | 24 | [[nodiscard]] char const* moduleName() const override; |
27 | DeepPrelude* newDeepObjectInternal(lua_State* L_) const override; | 25 | [[nodiscard]] DeepPrelude* newDeepObjectInternal(lua_State* L_) const override; |
28 | }; | 26 | }; |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 9bc71e1..be331a1 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #include "lualib.h" | 8 | #include "lualib.h" |
@@ -65,17 +66,17 @@ template <typename... ARGS> | |||
65 | #define DEBUGSPEW_CODE(_code) _code | 66 | #define DEBUGSPEW_CODE(_code) _code |
66 | #define DEBUGSPEW_OR_NOT(a_, b_) a_ | 67 | #define DEBUGSPEW_OR_NOT(a_, b_) a_ |
67 | #define DEBUGSPEW_PARAM_COMMA(param_) param_, | 68 | #define DEBUGSPEW_PARAM_COMMA(param_) param_, |
68 | #define DEBUGSPEW_COMMA_PARAM( param_) , param_ | 69 | #define DEBUGSPEW_COMMA_PARAM(param_) , param_ |
69 | #else // USE_DEBUG_SPEW() | 70 | #else // USE_DEBUG_SPEW() |
70 | #define DEBUGSPEW_CODE(_code) | 71 | #define DEBUGSPEW_CODE(_code) |
71 | #define DEBUGSPEW_OR_NOT(a_, b_) b_ | 72 | #define DEBUGSPEW_OR_NOT(a_, b_) b_ |
72 | #define DEBUGSPEW_PARAM_COMMA(param_) | 73 | #define DEBUGSPEW_PARAM_COMMA(param_) |
73 | #define DEBUGSPEW_COMMA_PARAM( param_) | 74 | #define DEBUGSPEW_COMMA_PARAM(param_) |
74 | #endif // USE_DEBUG_SPEW() | 75 | #endif // USE_DEBUG_SPEW() |
75 | 76 | ||
76 | #ifdef NDEBUG | 77 | #ifdef NDEBUG |
77 | 78 | ||
78 | #define LUA_ASSERT(L,c) ; //nothing | 79 | #define LUA_ASSERT(L, c) ; // nothing |
79 | 80 | ||
80 | #define STACK_CHECK_START_REL(L, offset_) | 81 | #define STACK_CHECK_START_REL(L, offset_) |
81 | #define STACK_CHECK_START_ABS(L, offset_) | 82 | #define STACK_CHECK_START_ABS(L, offset_) |
@@ -87,8 +88,7 @@ template <typename... ARGS> | |||
87 | 88 | ||
88 | inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t const line_, char const* txt_) | 89 | inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t const line_, char const* txt_) |
89 | { | 90 | { |
90 | if (!cond_) | 91 | if (!cond_) { |
91 | { | ||
92 | raise_luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); | 92 | raise_luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); |
93 | } | 93 | } |
94 | } | 94 | } |
@@ -120,8 +120,7 @@ class StackChecker | |||
120 | : m_L{ L_ } | 120 | : m_L{ L_ } |
121 | , m_oldtop{ lua_gettop(L_) - offset_ } | 121 | , m_oldtop{ lua_gettop(L_) - offset_ } |
122 | { | 122 | { |
123 | if ((offset_ < 0) || (m_oldtop < 0)) | 123 | if ((offset_ < 0) || (m_oldtop < 0)) { |
124 | { | ||
125 | assert(false); | 124 | assert(false); |
126 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); | 125 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); |
127 | } | 126 | } |
@@ -131,8 +130,7 @@ class StackChecker | |||
131 | : m_L{ L_ } | 130 | : m_L{ L_ } |
132 | , m_oldtop{ 0 } | 131 | , m_oldtop{ 0 } |
133 | { | 132 | { |
134 | if (lua_gettop(m_L) != pos_) | 133 | if (lua_gettop(m_L) != pos_) { |
135 | { | ||
136 | assert(false); | 134 | assert(false); |
137 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); | 135 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); |
138 | } | 136 | } |
@@ -148,11 +146,9 @@ class StackChecker | |||
148 | // verify if the distance between the current top and the initial one is what we expect | 146 | // verify if the distance between the current top and the initial one is what we expect |
149 | void check(int expected_, char const* file_, size_t const line_) | 147 | void check(int expected_, char const* file_, size_t const line_) |
150 | { | 148 | { |
151 | if (expected_ != LUA_MULTRET) | 149 | if (expected_ != LUA_MULTRET) { |
152 | { | ||
153 | int const actual{ lua_gettop(m_L) - m_oldtop }; | 150 | int const actual{ lua_gettop(m_L) - m_oldtop }; |
154 | if (actual != expected_) | 151 | if (actual != expected_) { |
155 | { | ||
156 | assert(false); | 152 | assert(false); |
157 | raise_luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); | 153 | raise_luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); |
158 | } | 154 | } |
@@ -160,10 +156,26 @@ class StackChecker | |||
160 | } | 156 | } |
161 | }; | 157 | }; |
162 | 158 | ||
163 | #define STACK_CHECK_START_REL(L, offset_) StackChecker stackChecker_##L{L, StackChecker::Relative{ offset_ }, __FILE__, __LINE__} | 159 | #define STACK_CHECK_START_REL(L, offset_) \ |
164 | #define STACK_CHECK_START_ABS(L, offset_) StackChecker stackChecker_##L{L, StackChecker::Absolute{ offset_ }, __FILE__, __LINE__} | 160 | StackChecker stackChecker_##L \ |
165 | #define STACK_CHECK_RESET_REL(L, offset_) stackChecker_##L = StackChecker{L, StackChecker::Relative{ offset_ }, __FILE__, __LINE__} | 161 | { \ |
166 | #define STACK_CHECK_RESET_ABS(L, offset_) stackChecker_##L = StackChecker{L, StackChecker::Absolute{ offset_ }, __FILE__, __LINE__} | 162 | L, StackChecker::Relative{ offset_ }, __FILE__, __LINE__ \ |
163 | } | ||
164 | #define STACK_CHECK_START_ABS(L, offset_) \ | ||
165 | StackChecker stackChecker_##L \ | ||
166 | { \ | ||
167 | L, StackChecker::Absolute{ offset_ }, __FILE__, __LINE__ \ | ||
168 | } | ||
169 | #define STACK_CHECK_RESET_REL(L, offset_) \ | ||
170 | stackChecker_##L = StackChecker \ | ||
171 | { \ | ||
172 | L, StackChecker::Relative{ offset_ }, __FILE__, __LINE__ \ | ||
173 | } | ||
174 | #define STACK_CHECK_RESET_ABS(L, offset_) \ | ||
175 | stackChecker_##L = StackChecker \ | ||
176 | { \ | ||
177 | L, StackChecker::Absolute{ offset_ }, __FILE__, __LINE__ \ | ||
178 | } | ||
167 | #define STACK_CHECK(L, offset_) stackChecker_##L.check(offset_, __FILE__, __LINE__) | 179 | #define STACK_CHECK(L, offset_) stackChecker_##L.check(offset_, __FILE__, __LINE__) |
168 | 180 | ||
169 | #endif // NDEBUG | 181 | #endif // NDEBUG |
@@ -172,8 +184,7 @@ class StackChecker | |||
172 | 184 | ||
173 | inline void STACK_GROW(lua_State* L, int n_) | 185 | inline void STACK_GROW(lua_State* L, int n_) |
174 | { | 186 | { |
175 | if (!lua_checkstack(L, n_)) | 187 | if (!lua_checkstack(L, n_)) { |
176 | { | ||
177 | raise_luaL_error(L, "Cannot grow stack!"); | 188 | raise_luaL_error(L, "Cannot grow stack!"); |
178 | } | 189 | } |
179 | } | 190 | } |
@@ -185,23 +196,20 @@ inline void STACK_GROW(lua_State* L, int n_) | |||
185 | // ################################################################################################# | 196 | // ################################################################################################# |
186 | 197 | ||
187 | // a small helper to extract a full userdata pointer from the stack in a safe way | 198 | // a small helper to extract a full userdata pointer from the stack in a safe way |
188 | template<typename T> | 199 | template <typename T> |
189 | [[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) | 200 | [[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) |
190 | { | 201 | { |
191 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); | 202 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); |
192 | return static_cast<T*>(lua_touserdata(L, index_)); | 203 | return static_cast<T*>(lua_touserdata(L, index_)); |
193 | } | 204 | } |
194 | 205 | ||
195 | template<typename T> | 206 | template <typename T> |
196 | [[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) | 207 | [[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) |
197 | { | 208 | { |
198 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_islightuserdata(L, index_)); | 209 | LUA_ASSERT(L, lua_isnil(L, index_) || lua_islightuserdata(L, index_)); |
199 | if constexpr (std::is_pointer_v<T>) | 210 | if constexpr (std::is_pointer_v<T>) { |
200 | { | ||
201 | return static_cast<T>(lua_touserdata(L, index_)); | 211 | return static_cast<T>(lua_touserdata(L, index_)); |
202 | } | 212 | } else { |
203 | else | ||
204 | { | ||
205 | return static_cast<T*>(lua_touserdata(L, index_)); | 213 | return static_cast<T*>(lua_touserdata(L, index_)); |
206 | } | 214 | } |
207 | } | 215 | } |
@@ -223,23 +231,27 @@ template <typename T, auto = [] {}, typename specialization = void> | |||
223 | class Unique | 231 | class Unique |
224 | { | 232 | { |
225 | private: | 233 | private: |
226 | |||
227 | T m_val; | 234 | T m_val; |
228 | 235 | ||
229 | public: | 236 | public: |
230 | |||
231 | Unique() = default; | 237 | Unique() = default; |
232 | operator T() const { return m_val; } | 238 | operator T() const { return m_val; } |
233 | explicit Unique(T b_) : m_val{ b_ } {} | 239 | explicit Unique(T b_) |
240 | : m_val{ b_ } | ||
241 | { | ||
242 | } | ||
234 | }; | 243 | }; |
235 | 244 | ||
236 | template <typename T, auto lambda> | 245 | template <typename T, auto lambda> |
237 | class Unique<T, lambda, std::enable_if_t<!std::is_scalar_v<T>>> : public T | 246 | class Unique<T, lambda, std::enable_if_t<!std::is_scalar_v<T>>> |
247 | : public T | ||
238 | { | 248 | { |
239 | public: | 249 | public: |
240 | |||
241 | using T::T; | 250 | using T::T; |
242 | explicit Unique(T const& b_) : T{ b_ } {} | 251 | explicit Unique(T const& b_) |
252 | : T{ b_ } | ||
253 | { | ||
254 | } | ||
243 | }; | 255 | }; |
244 | 256 | ||
245 | // ################################################################################################# | 257 | // ################################################################################################# |
@@ -252,14 +264,16 @@ using DestState = Unique<lua_State*>; | |||
252 | // A helper to issue an error if the provided optional doesn't contain a value | 264 | // A helper to issue an error if the provided optional doesn't contain a value |
253 | // we can't use std::optional::value_or(luaL_error(...)), because the 'or' value is always evaluated | 265 | // we can't use std::optional::value_or(luaL_error(...)), because the 'or' value is always evaluated |
254 | template <typename T> | 266 | template <typename T> |
255 | concept IsOptional = requires(T x){ x.value_or(T{}); }; | 267 | concept IsOptional = requires(T x) |
268 | { | ||
269 | x.value_or(T{}); | ||
270 | }; | ||
256 | 271 | ||
257 | template<typename T, typename ...Ts> | 272 | template <typename T, typename... Ts> |
258 | requires IsOptional<T> | 273 | requires IsOptional<T> |
259 | typename T::value_type const& OptionalValue(T const& x_, Ts... args_) | 274 | typename T::value_type const& OptionalValue(T const& x_, Ts... args_) |
260 | { | 275 | { |
261 | if (!x_.has_value()) | 276 | if (!x_.has_value()) { |
262 | { | ||
263 | raise_luaL_error(std::forward<Ts>(args_)...); | 277 | raise_luaL_error(std::forward<Ts>(args_)...); |
264 | } | 278 | } |
265 | return x_.value(); | 279 | return x_.value(); |
diff --git a/src/platform.h b/src/platform.h index b10f0ad..5a740e5 100644 --- a/src/platform.h +++ b/src/platform.h | |||
@@ -1,22 +1,22 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef _WIN32_WCE | 3 | #ifdef _WIN32_WCE |
4 | #define PLATFORM_POCKETPC | 4 | #define PLATFORM_POCKETPC |
5 | #elif defined(_XBOX) | 5 | #elif defined(_XBOX) |
6 | #define PLATFORM_XBOX | 6 | #define PLATFORM_XBOX |
7 | #elif (defined _WIN32) | 7 | #elif (defined _WIN32) |
8 | #define PLATFORM_WIN32 | 8 | #define PLATFORM_WIN32 |
9 | #define NOMINMAX | 9 | #define NOMINMAX |
10 | #elif (defined __linux__) | 10 | #elif (defined __linux__) |
11 | #define PLATFORM_LINUX | 11 | #define PLATFORM_LINUX |
12 | #elif (defined __APPLE__) && (defined __MACH__) | 12 | #elif (defined __APPLE__) && (defined __MACH__) |
13 | #define PLATFORM_OSX | 13 | #define PLATFORM_OSX |
14 | #elif (defined __NetBSD__) || (defined __FreeBSD__) || (defined BSD) | 14 | #elif (defined __NetBSD__) || (defined __FreeBSD__) || (defined BSD) |
15 | #define PLATFORM_BSD | 15 | #define PLATFORM_BSD |
16 | #elif (defined __QNX__) | 16 | #elif (defined __QNX__) |
17 | #define PLATFORM_QNX | 17 | #define PLATFORM_QNX |
18 | #elif (defined __CYGWIN__) | 18 | #elif (defined __CYGWIN__) |
19 | #define PLATFORM_CYGWIN | 19 | #define PLATFORM_CYGWIN |
20 | #else | 20 | #else |
21 | #error "Unknown platform!" | 21 | #error "Unknown platform!" |
22 | #endif | 22 | #endif |
diff --git a/src/threading.h b/src/threading.h index 7d24ef0..d88d308 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -7,11 +7,11 @@ | |||
7 | #define THREADAPI_WINDOWS 1 | 7 | #define THREADAPI_WINDOWS 1 |
8 | #define THREADAPI_PTHREAD 2 | 8 | #define THREADAPI_PTHREAD 2 |
9 | 9 | ||
10 | #if (defined( PLATFORM_XBOX) || defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC)) | 10 | #if (defined(PLATFORM_XBOX) || defined(PLATFORM_WIN32) || defined(PLATFORM_POCKETPC)) |
11 | //#pragma message ( "THREADAPI_WINDOWS" ) | 11 | // #pragma message ( "THREADAPI_WINDOWS" ) |
12 | #define THREADAPI THREADAPI_WINDOWS | 12 | #define THREADAPI THREADAPI_WINDOWS |
13 | #else // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 13 | #else // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
14 | //#pragma message ( "THREADAPI_PTHREAD" ) | 14 | // #pragma message ( "THREADAPI_PTHREAD" ) |
15 | #define THREADAPI THREADAPI_PTHREAD | 15 | #define THREADAPI THREADAPI_PTHREAD |
16 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 16 | #endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
17 | 17 | ||
diff --git a/src/tools.h b/src/tools.h index 53edbe2..f83a01c 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -32,7 +32,6 @@ using SourceIndex = Unique<int>; | |||
32 | class InterCopyContext | 32 | class InterCopyContext |
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | |||
36 | Universe* const U; | 35 | Universe* const U; |
37 | DestState const L2; | 36 | DestState const L2; |
38 | SourceState const L1; | 37 | SourceState const L1; |
@@ -43,7 +42,6 @@ class InterCopyContext | |||
43 | char const* name; // that one can change when we reuse the context | 42 | char const* name; // that one can change when we reuse the context |
44 | 43 | ||
45 | private: | 44 | private: |
46 | |||
47 | // for use in copy_cached_func | 45 | // for use in copy_cached_func |
48 | void copy_func() const; | 46 | void copy_func() const; |
49 | void lookup_native_func() const; | 47 | void lookup_native_func() const; |
@@ -71,7 +69,6 @@ class InterCopyContext | |||
71 | [[nodiscard]] bool inter_copy_userdata() const; | 69 | [[nodiscard]] bool inter_copy_userdata() const; |
72 | 70 | ||
73 | public: | 71 | public: |
74 | |||
75 | [[nodiscard]] bool inter_copy_one() const; | 72 | [[nodiscard]] bool inter_copy_one() const; |
76 | [[nodiscard]] InterCopyResult inter_copy_package() const; | 73 | [[nodiscard]] InterCopyResult inter_copy_package() const; |
77 | [[nodiscard]] InterCopyResult inter_copy(int n_) const; | 74 | [[nodiscard]] InterCopyResult inter_copy(int n_) const; |
diff --git a/src/uniquekey.h b/src/uniquekey.h index 738cb51..984ef50 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h | |||
@@ -10,11 +10,9 @@ | |||
10 | class UniqueKey | 10 | class UniqueKey |
11 | { | 11 | { |
12 | protected: | 12 | protected: |
13 | |||
14 | uintptr_t const m_storage{ 0 }; | 13 | uintptr_t const m_storage{ 0 }; |
15 | 14 | ||
16 | public: | 15 | public: |
17 | |||
18 | char const* m_debugName{ nullptr }; | 16 | char const* m_debugName{ nullptr }; |
19 | 17 | ||
20 | // --------------------------------------------------------------------------------------------- | 18 | // --------------------------------------------------------------------------------------------- |
@@ -45,10 +43,10 @@ class UniqueKey | |||
45 | 43 | ||
46 | // ################################################################################################# | 44 | // ################################################################################################# |
47 | 45 | ||
48 | class RegistryUniqueKey : public UniqueKey | 46 | class RegistryUniqueKey |
47 | : public UniqueKey | ||
49 | { | 48 | { |
50 | public: | 49 | public: |
51 | |||
52 | using UniqueKey::UniqueKey; | 50 | using UniqueKey::UniqueKey; |
53 | 51 | ||
54 | // --------------------------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------------------------- |
@@ -64,9 +62,9 @@ class RegistryUniqueKey : public UniqueKey | |||
64 | void setValue(lua_State* L_, OP operation_) const | 62 | void setValue(lua_State* L_, OP operation_) const |
65 | { | 63 | { |
66 | // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) | 64 | // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) |
67 | pushKey(L_); // ... key | 65 | pushKey(L_); // ... key |
68 | operation_(L_); // ... key value | 66 | operation_(L_); // ... key value |
69 | lua_rawset(L_, LUA_REGISTRYINDEX); // ... | 67 | lua_rawset(L_, LUA_REGISTRYINDEX); // ... |
70 | } | 68 | } |
71 | // --------------------------------------------------------------------------------------------- | 69 | // --------------------------------------------------------------------------------------------- |
72 | template <typename T> | 70 | template <typename T> |
@@ -86,7 +84,7 @@ class RegistryUniqueKey : public UniqueKey | |||
86 | STACK_GROW(L_, 1); | 84 | STACK_GROW(L_, 1); |
87 | STACK_CHECK_START_REL(L_, 0); | 85 | STACK_CHECK_START_REL(L_, 0); |
88 | pushValue(L_); | 86 | pushValue(L_); |
89 | bool const value{ lua_toboolean(L_, -1) ? true : false}; // bool/nil | 87 | bool const value{ lua_toboolean(L_, -1) ? true : false }; // bool/nil |
90 | lua_pop(L_, 1); | 88 | lua_pop(L_, 1); |
91 | STACK_CHECK(L_, 0); | 89 | STACK_CHECK(L_, 0); |
92 | return value; | 90 | return value; |
diff --git a/src/universe.h b/src/universe.h index bdc871d..128c4d9 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -1,7 +1,8 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #ifdef __cplusplus | 3 | #ifdef __cplusplus |
4 | extern "C" { | 4 | extern "C" |
5 | { | ||
5 | #endif // __cplusplus | 6 | #endif // __cplusplus |
6 | #include "lua.h" | 7 | #include "lua.h" |
7 | #ifdef __cplusplus | 8 | #ifdef __cplusplus |
@@ -20,9 +21,7 @@ struct DeepPrelude; | |||
20 | struct Keepers; | 21 | struct Keepers; |
21 | class Lane; | 22 | class Lane; |
22 | 23 | ||
23 | /* | 24 | // Do we want to activate full lane tracking feature? |
24 | * Do we want to activate full lane tracking feature? (EXPERIMENTAL) | ||
25 | */ | ||
26 | #define HAVE_LANE_TRACKING() 1 | 25 | #define HAVE_LANE_TRACKING() 1 |
27 | 26 | ||
28 | // ################################################################################################# | 27 | // ################################################################################################# |
@@ -31,7 +30,6 @@ class Lane; | |||
31 | class AllocatorDefinition | 30 | class AllocatorDefinition |
32 | { | 31 | { |
33 | public: | 32 | public: |
34 | |||
35 | lua_Alloc m_allocF{ nullptr }; | 33 | lua_Alloc m_allocF{ nullptr }; |
36 | void* m_allocUD{ nullptr }; | 34 | void* m_allocUD{ nullptr }; |
37 | 35 | ||
@@ -76,10 +74,10 @@ class AllocatorDefinition | |||
76 | // ################################################################################################# | 74 | // ################################################################################################# |
77 | 75 | ||
78 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator | 76 | // mutex-protected allocator for use with Lua states that share a non-threadsafe allocator |
79 | class ProtectedAllocator : public AllocatorDefinition | 77 | class ProtectedAllocator |
78 | : public AllocatorDefinition | ||
80 | { | 79 | { |
81 | private: | 80 | private: |
82 | |||
83 | std::mutex m_lock; | 81 | std::mutex m_lock; |
84 | 82 | ||
85 | [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) | 83 | [[nodiscard]] static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) |
@@ -90,14 +88,13 @@ class ProtectedAllocator : public AllocatorDefinition | |||
90 | } | 88 | } |
91 | 89 | ||
92 | public: | 90 | public: |
93 | |||
94 | // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) | 91 | // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) |
95 | [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept = delete; | 92 | [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept = delete; |
96 | static void operator delete(void* p_, lua_State* L) = delete; | 93 | static void operator delete(void* p_, lua_State* L) = delete; |
97 | 94 | ||
98 | AllocatorDefinition makeDefinition() | 95 | AllocatorDefinition makeDefinition() |
99 | { | 96 | { |
100 | return AllocatorDefinition{ protected_lua_Alloc, this}; | 97 | return AllocatorDefinition{ protected_lua_Alloc, this }; |
101 | } | 98 | } |
102 | 99 | ||
103 | void installIn(lua_State* L) | 100 | void installIn(lua_State* L) |
@@ -108,8 +105,7 @@ class ProtectedAllocator : public AllocatorDefinition | |||
108 | void removeFrom(lua_State* L) | 105 | void removeFrom(lua_State* L) |
109 | { | 106 | { |
110 | // remove the protected allocator, if any | 107 | // remove the protected allocator, if any |
111 | if (m_allocF != nullptr) | 108 | if (m_allocF != nullptr) { |
112 | { | ||
113 | // install the non-protected allocator | 109 | // install the non-protected allocator |
114 | lua_setallocf(L, m_allocF, m_allocUD); | 110 | lua_setallocf(L, m_allocF, m_allocUD); |
115 | } | 111 | } |
@@ -123,7 +119,6 @@ class ProtectedAllocator : public AllocatorDefinition | |||
123 | class Universe | 119 | class Universe |
124 | { | 120 | { |
125 | public: | 121 | public: |
126 | |||
127 | #ifdef PLATFORM_LINUX | 122 | #ifdef PLATFORM_LINUX |
128 | // Linux needs to check, whether it's been run as root | 123 | // Linux needs to check, whether it's been run as root |
129 | bool const m_sudo{ geteuid() == 0 }; | 124 | bool const m_sudo{ geteuid() == 0 }; |
@@ -197,11 +192,9 @@ void universe_store(lua_State* L, Universe* U); | |||
197 | class DebugSpewIndentScope | 192 | class DebugSpewIndentScope |
198 | { | 193 | { |
199 | private: | 194 | private: |
200 | |||
201 | Universe* const U; | 195 | Universe* const U; |
202 | 196 | ||
203 | public: | 197 | public: |
204 | |||
205 | static char const* const debugspew_indent; | 198 | static char const* const debugspew_indent; |
206 | 199 | ||
207 | DebugSpewIndentScope(Universe* U_) | 200 | DebugSpewIndentScope(Universe* U_) |