aboutsummaryrefslogtreecommitdiff
path: root/src/tools.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/tools.c b/src/tools.c
index 59037e6..3e3efeb 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -31,22 +31,22 @@ THE SOFTWARE.
31=============================================================================== 31===============================================================================
32*/ 32*/
33 33
34#include "compat.h"
35#include "universe.h"
36#include "tools.h"
37#include "keeper.h"
38#include "lanes.h"
39
40#include <stdio.h> 34#include <stdio.h>
41#include <string.h> 35#include <string.h>
42#include <ctype.h> 36#include <ctype.h>
43#include <stdlib.h> 37#include <stdlib.h>
44#if !defined(__APPLE__) 38#if !defined(__APPLE__)
45#include <malloc.h> 39#include <malloc.h>
46#endif 40#endif // __APPLE__
41
42#include "tools.h"
43#include "compat.h"
44#include "universe.h"
45#include "keeper.h"
46#include "lanes.h"
47 47
48// functions implemented in deep.c 48// functions implemented in deep.c
49extern luaG_IdFunction copydeep( struct s_Universe* U, lua_State* L, lua_State* L2, int index, enum eLookupMode mode_); 49extern luaG_IdFunction copydeep( Universe* U, lua_State* L, lua_State* L2, int index, enum eLookupMode mode_);
50extern void push_registry_subtable( lua_State* L, void* key_); 50extern void push_registry_subtable( lua_State* L, void* key_);
51 51
52char const* const CONFIG_REGKEY = "ee932492-a654-4506-9da8-f16540bdb5d4"; 52char const* const CONFIG_REGKEY = "ee932492-a654-4506-9da8-f16540bdb5d4";
@@ -105,7 +105,7 @@ void luaG_dump( lua_State* L)
105 fprintf( stderr, "\n"); 105 fprintf( stderr, "\n");
106} 106}
107 107
108void initialize_on_state_create( struct s_Universe* U, lua_State* L) 108void initialize_on_state_create( Universe* U, lua_State* L)
109{ 109{
110 STACK_CHECK( L); 110 STACK_CHECK( L);
111 lua_getfield( L, -1, "on_state_create"); // settings on_state_create|nil 111 lua_getfield( L, -1, "on_state_create"); // settings on_state_create|nil
@@ -139,7 +139,7 @@ void initialize_on_state_create( struct s_Universe* U, lua_State* L)
139// ################################################################################################ 139// ################################################################################################
140 140
141// just like lua_xmove, args are (from, to) 141// just like lua_xmove, args are (from, to)
142void luaG_copy_one_time_settings( struct s_Universe* U, lua_State* L, lua_State* L2) 142void luaG_copy_one_time_settings( Universe* U, lua_State* L, lua_State* L2)
143{ 143{
144 STACK_GROW( L, 1); 144 STACK_GROW( L, 1);
145 // copy settings from from source to destination registry 145 // copy settings from from source to destination registry
@@ -198,7 +198,7 @@ static const luaL_Reg libs[] =
198 { NULL, NULL } 198 { NULL, NULL }
199}; 199};
200 200
201static void open1lib( struct s_Universe* U, lua_State* L, char const* name_, size_t len_, lua_State* from_) 201static void open1lib( Universe* U, lua_State* L, char const* name_, size_t len_, lua_State* from_)
202{ 202{
203 int i; 203 int i;
204 for( i = 0; libs[i].name; ++ i) 204 for( i = 0; libs[i].name; ++ i)
@@ -341,7 +341,7 @@ static void update_lookup_entry( lua_State* L, int _ctx_base, int _depth)
341 size_t prevNameLength, newNameLength; 341 size_t prevNameLength, newNameLength;
342 char const* prevName; 342 char const* prevName;
343 DEBUGSPEW_CODE( char const *newName); 343 DEBUGSPEW_CODE( char const *newName);
344 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L)); 344 DEBUGSPEW_CODE( Universe* U = universe_get( L));
345 345
346 STACK_CHECK( L); 346 STACK_CHECK( L);
347 // first, raise an error if the function is already known 347 // first, raise an error if the function is already known
@@ -412,7 +412,7 @@ static void populate_func_lookup_table_recur( lua_State* L, int _ctx_base, int _
412 int const cache = _ctx_base + 2; 412 int const cache = _ctx_base + 2;
413 // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search) 413 // we need to remember subtables to process them after functions encountered at the current depth (breadth-first search)
414 int const breadth_first_cache = lua_gettop( L) + 1; 414 int const breadth_first_cache = lua_gettop( L) + 1;
415 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L)); 415 DEBUGSPEW_CODE( Universe* U = universe_get( L));
416 416
417 STACK_GROW( L, 6); 417 STACK_GROW( L, 6);
418 // slot _i contains a table where we search for functions (or a full userdata with a metatable) 418 // slot _i contains a table where we search for functions (or a full userdata with a metatable)
@@ -530,7 +530,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_)
530 int const ctx_base = lua_gettop( L) + 1; 530 int const ctx_base = lua_gettop( L) + 1;
531 int const in_base = lua_absindex( L, _i); 531 int const in_base = lua_absindex( L, _i);
532 int start_depth = 0; 532 int start_depth = 0;
533 DEBUGSPEW_CODE( struct s_Universe* U = universe_get( L)); 533 DEBUGSPEW_CODE( Universe* U = universe_get( L));
534 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL")); 534 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: populate_func_lookup_table('%s')\n" INDENT_END, L, name_ ? name_ : "NULL"));
535 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 535 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
536 STACK_GROW( L, 3); 536 STACK_GROW( L, 3);
@@ -585,7 +585,7 @@ void populate_func_lookup_table( lua_State* L, int _i, char const* name_)
585 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 585 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
586} 586}
587 587
588void call_on_state_create( struct s_Universe* U, lua_State* L, lua_State* from_, enum eLookupMode mode_) 588void call_on_state_create( Universe* U, lua_State* L, lua_State* from_, enum eLookupMode mode_)
589{ 589{
590 if( U->on_state_create_func != NULL) 590 if( U->on_state_create_func != NULL)
591 { 591 {
@@ -630,7 +630,7 @@ void call_on_state_create( struct s_Universe* U, lua_State* L, lua_State* from_,
630 * *NOT* called for keeper states! 630 * *NOT* called for keeper states!
631 * 631 *
632 */ 632 */
633lua_State* luaG_newstate( struct s_Universe* U, lua_State* from_, char const* libs_) 633lua_State* luaG_newstate( Universe* U, lua_State* from_, char const* libs_)
634{ 634{
635 // re-use alloc function from the originating state 635 // re-use alloc function from the originating state
636#if PROPAGATE_ALLOCF 636#if PROPAGATE_ALLOCF
@@ -761,7 +761,7 @@ lua_State* luaG_newstate( struct s_Universe* U, lua_State* from_, char const* li
761/* 761/*
762* Get a unique ID for metatable at [i]. 762* Get a unique ID for metatable at [i].
763*/ 763*/
764static uint_t get_mt_id( struct s_Universe* U, lua_State* L, int i) 764static uint_t get_mt_id( Universe* U, lua_State* L, int i)
765{ 765{
766 uint_t id; 766 uint_t id;
767 767
@@ -830,7 +830,7 @@ static int table_lookup_sentinel( lua_State* L)
830 */ 830 */
831static char const* find_lookup_name( lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_, size_t* len_) 831static char const* find_lookup_name( lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_, size_t* len_)
832{ 832{
833 DEBUGSPEW_CODE( struct s_Universe* const U = universe_get( L)); 833 DEBUGSPEW_CODE( Universe* const U = universe_get( L));
834 char const* fqn; 834 char const* fqn;
835 ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... 835 ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ...
836 STACK_CHECK( L); 836 STACK_CHECK( L);
@@ -1276,9 +1276,9 @@ enum e_vt
1276 VT_KEY, 1276 VT_KEY,
1277 VT_METATABLE 1277 VT_METATABLE
1278}; 1278};
1279static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt value_type, enum eLookupMode mode_, char const* upName_); 1279static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt value_type, enum eLookupMode mode_, char const* upName_);
1280 1280
1281static void inter_copy_func( struct s_Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_) 1281static void inter_copy_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_)
1282{ 1282{
1283 int n, needToPush; 1283 int n, needToPush;
1284 luaL_Buffer b; 1284 luaL_Buffer b;
@@ -1427,7 +1427,7 @@ static void inter_copy_func( struct s_Universe* U, lua_State* L2, uint_t L2_cach
1427 * 1427 *
1428 * Always pushes a function to 'L2'. 1428 * Always pushes a function to 'L2'.
1429 */ 1429 */
1430static void push_cached_func( struct s_Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_) 1430static void push_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_)
1431{ 1431{
1432 FuncSubType funcSubType; 1432 FuncSubType funcSubType;
1433 /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions 1433 /*lua_CFunction cfunc =*/ luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions
@@ -1480,7 +1480,7 @@ static void push_cached_func( struct s_Universe* U, lua_State* L2, uint_t L2_cac
1480 } 1480 }
1481} 1481}
1482 1482
1483static void inter_copy_keyvaluepair( struct s_Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, enum eLookupMode mode_, char const* upName_) 1483static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, enum eLookupMode mode_, char const* upName_)
1484{ 1484{
1485 uint_t val_i = lua_gettop( L); 1485 uint_t val_i = lua_gettop( L);
1486 uint_t key_i = val_i - 1; 1486 uint_t key_i = val_i - 1;
@@ -1542,7 +1542,7 @@ static void inter_copy_keyvaluepair( struct s_Universe* U, lua_State* L2, uint_t
1542* 1542*
1543* Returns TRUE if value was pushed, FALSE if its type is non-supported. 1543* Returns TRUE if value was pushed, FALSE if its type is non-supported.
1544*/ 1544*/
1545static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, enum eLookupMode mode_, char const* upName_) 1545static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, enum eLookupMode mode_, char const* upName_)
1546{ 1546{
1547 bool_t ret = TRUE; 1547 bool_t ret = TRUE;
1548 bool_t ignore = FALSE; 1548 bool_t ignore = FALSE;
@@ -1809,7 +1809,7 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca
1809* 1809*
1810* Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. 1810* Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'.
1811*/ 1811*/
1812int luaG_inter_copy( struct s_Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_) 1812int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_)
1813{ 1813{
1814 uint_t top_L = lua_gettop( L); 1814 uint_t top_L = lua_gettop( L);
1815 uint_t top_L2 = lua_gettop( L2); 1815 uint_t top_L2 = lua_gettop( L2);
@@ -1867,14 +1867,14 @@ int luaG_inter_copy( struct s_Universe* U, lua_State* L, lua_State* L2, uint_t n
1867} 1867}
1868 1868
1869 1869
1870int luaG_inter_move( struct s_Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_) 1870int luaG_inter_move( Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_)
1871{ 1871{
1872 int ret = luaG_inter_copy( U, L, L2, n, mode_); 1872 int ret = luaG_inter_copy( U, L, L2, n, mode_);
1873 lua_pop( L, (int) n); 1873 lua_pop( L, (int) n);
1874 return ret; 1874 return ret;
1875} 1875}
1876 1876
1877int luaG_inter_copy_package( struct s_Universe* U, lua_State* L, lua_State* L2, int package_idx_, enum eLookupMode mode_) 1877int luaG_inter_copy_package( Universe* U, lua_State* L, lua_State* L2, int package_idx_, enum eLookupMode mode_)
1878{ 1878{
1879 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); 1879 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END));
1880 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1880 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
@@ -1941,7 +1941,7 @@ int luaG_new_require( lua_State* L)
1941{ 1941{
1942 int rc, i; 1942 int rc, i;
1943 int args = lua_gettop( L); 1943 int args = lua_gettop( L);
1944 struct s_Universe* U = universe_get( L); 1944 Universe* U = universe_get( L);
1945 //char const* modname = luaL_checkstring( L, 1); 1945 //char const* modname = luaL_checkstring( L, 1);
1946 1946
1947 STACK_GROW( L, args + 1); 1947 STACK_GROW( L, args + 1);
@@ -1974,7 +1974,7 @@ int luaG_new_require( lua_State* L)
1974/* 1974/*
1975* Serialize calls to 'require', if it exists 1975* Serialize calls to 'require', if it exists
1976*/ 1976*/
1977void serialize_require( struct s_Universe* U, lua_State* L) 1977void serialize_require( Universe* U, lua_State* L)
1978{ 1978{
1979 STACK_GROW( L, 1); 1979 STACK_GROW( L, 1);
1980 STACK_CHECK( L); 1980 STACK_CHECK( L);