diff options
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/state.cpp b/src/state.cpp index 496e21e..4a5f995 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -8,7 +8,7 @@ | |||
8 | =============================================================================== | 8 | =============================================================================== |
9 | 9 | ||
10 | Copyright (C) 2002-10 Asko Kauppi <akauppi@gmail.com> | 10 | Copyright (C) 2002-10 Asko Kauppi <akauppi@gmail.com> |
11 | 2011-21 benoit Germain <bnt.germain@gmail.com> | 11 | 2011-24 benoit Germain <bnt.germain@gmail.com> |
12 | 12 | ||
13 | Permission is hereby granted, free of charge, to any person obtaining a copy | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy |
14 | of this software and associated documentation files (the "Software"), to deal | 14 | of this software and associated documentation files (the "Software"), to deal |
@@ -79,6 +79,8 @@ THE SOFTWARE. | |||
79 | return lua_gettop(L); // result(s) | 79 | return lua_gettop(L); // result(s) |
80 | } | 80 | } |
81 | 81 | ||
82 | // ################################################################################################# | ||
83 | |||
82 | /* | 84 | /* |
83 | * Serialize calls to 'require', if it exists | 85 | * Serialize calls to 'require', if it exists |
84 | */ | 86 | */ |
@@ -117,6 +119,7 @@ void serialize_require(DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L) | |||
117 | return 1; | 119 | return 1; |
118 | } | 120 | } |
119 | 121 | ||
122 | // ################################################################################################# | ||
120 | 123 | ||
121 | static luaL_Reg const libs[] = | 124 | static luaL_Reg const libs[] = |
122 | { | 125 | { |
@@ -154,7 +157,9 @@ static luaL_Reg const libs[] = | |||
154 | { nullptr, nullptr } | 157 | { nullptr, nullptr } |
155 | }; | 158 | }; |
156 | 159 | ||
157 | static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) | 160 | // ################################################################################################# |
161 | |||
162 | static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, char const* name_, size_t len_) | ||
158 | { | 163 | { |
159 | int i; | 164 | int i; |
160 | for( i = 0; libs[i].name; ++ i) | 165 | for( i = 0; libs[i].name; ++ i) |
@@ -183,6 +188,7 @@ static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char con | |||
183 | } | 188 | } |
184 | } | 189 | } |
185 | 190 | ||
191 | // ################################################################################################# | ||
186 | 192 | ||
187 | // just like lua_xmove, args are (from, to) | 193 | // just like lua_xmove, args are (from, to) |
188 | static void copy_one_time_settings(Universe* U, Source L, Dest L2) | 194 | static void copy_one_time_settings(Universe* U, Source L, Dest L2) |
@@ -194,19 +200,21 @@ static void copy_one_time_settings(Universe* U, Source L, Dest L2) | |||
194 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); | 200 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); |
195 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); | 201 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); |
196 | 202 | ||
197 | CONFIG_REGKEY.pushValue(L); // config | 203 | CONFIG_REGKEY.pushValue(L); // config |
198 | // copy settings from from source to destination registry | 204 | // copy settings from from source to destination registry |
199 | if( luaG_inter_move( U, L, L2, 1, LookupMode::LaneBody) < 0) // // config | 205 | if (luaG_inter_move(U, L, L2, 1, LookupMode::LaneBody) != InterCopyResult::Success) // // config |
200 | { | 206 | { |
201 | (void) luaL_error( L, "failed to copy settings when loading lanes.core"); | 207 | luaL_error( L, "failed to copy settings when loading lanes.core"); // doesn't return |
202 | } | 208 | } |
203 | // set L2:_R[CONFIG_REGKEY] = settings | 209 | // set L2:_R[CONFIG_REGKEY] = settings |
204 | CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config | 210 | CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config |
205 | STACK_CHECK( L2, 0); | 211 | STACK_CHECK(L2, 0); |
206 | STACK_CHECK( L, 0); | 212 | STACK_CHECK(L, 0); |
207 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); | 213 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); |
208 | } | 214 | } |
209 | 215 | ||
216 | // ################################################################################################# | ||
217 | |||
210 | void initialize_on_state_create( Universe* U, lua_State* L) | 218 | void initialize_on_state_create( Universe* U, lua_State* L) |
211 | { | 219 | { |
212 | STACK_CHECK_START_REL(L, 1); // settings | 220 | STACK_CHECK_START_REL(L, 1); // settings |
@@ -238,7 +246,9 @@ void initialize_on_state_create( Universe* U, lua_State* L) | |||
238 | STACK_CHECK(L, 1); | 246 | STACK_CHECK(L, 1); |
239 | } | 247 | } |
240 | 248 | ||
241 | lua_State* create_state( Universe* U, lua_State* from_) | 249 | // ################################################################################################# |
250 | |||
251 | lua_State* create_state(Universe* U, lua_State* from_) | ||
242 | { | 252 | { |
243 | lua_State* L; | 253 | lua_State* L; |
244 | #if LUAJIT_FLAVOR() == 64 | 254 | #if LUAJIT_FLAVOR() == 64 |
@@ -264,11 +274,13 @@ lua_State* create_state( Universe* U, lua_State* from_) | |||
264 | 274 | ||
265 | if (L == nullptr) | 275 | if (L == nullptr) |
266 | { | 276 | { |
267 | std::ignore = luaL_error( from_, "luaG_newstate() failed while creating state; out of memory"); | 277 | luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); // doesn't return |
268 | } | 278 | } |
269 | return L; | 279 | return L; |
270 | } | 280 | } |
271 | 281 | ||
282 | // ################################################################################################# | ||
283 | |||
272 | void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) | 284 | void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) |
273 | { | 285 | { |
274 | if (U->on_state_create_func != nullptr) | 286 | if (U->on_state_create_func != nullptr) |
@@ -304,6 +316,8 @@ void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMod | |||
304 | } | 316 | } |
305 | } | 317 | } |
306 | 318 | ||
319 | // ################################################################################################# | ||
320 | |||
307 | /* | 321 | /* |
308 | * Like 'luaL_openlibs()' but allows the set of libraries be selected | 322 | * Like 'luaL_openlibs()' but allows the set of libraries be selected |
309 | * | 323 | * |