Style fixes. Comments fixes. Fixing cmd options. etc
This commit is contained in:
parent
a87710275d
commit
4b0ed73317
2 changed files with 179 additions and 161 deletions
|
|
@ -32,7 +32,7 @@ extern "C" {
|
||||||
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
|
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
|
||||||
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
|
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
|
||||||
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
|
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
|
||||||
// Those two types of constants are not supported in elua
|
/* Those two types of constants are not supported in elua */
|
||||||
# define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL
|
# define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL
|
||||||
# define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
|
# define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
|
||||||
#else /* SWIG_LUA_FLAVOR_LUA */
|
#else /* SWIG_LUA_FLAVOR_LUA */
|
||||||
|
|
@ -137,7 +137,7 @@ typedef struct {
|
||||||
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
|
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
|
||||||
typedef const LUA_REG_TYPE swig_lua_method;
|
typedef const LUA_REG_TYPE swig_lua_method;
|
||||||
typedef const LUA_REG_TYPE swig_lua_const_info;
|
typedef const LUA_REG_TYPE swig_lua_const_info;
|
||||||
#else // Normal lua
|
#else /* Normal lua */
|
||||||
typedef luaL_Reg swig_lua_method;
|
typedef luaL_Reg swig_lua_method;
|
||||||
|
|
||||||
/* Constant information structure */
|
/* Constant information structure */
|
||||||
|
|
@ -159,28 +159,27 @@ typedef struct {
|
||||||
} swig_lua_attribute;
|
} swig_lua_attribute;
|
||||||
|
|
||||||
|
|
||||||
struct _swig_lua_class;
|
struct swig_lua_class;
|
||||||
// Can be used to create namespaces. Currently used to
|
/* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */
|
||||||
// wrap class static methods/variables/constants
|
typedef struct swig_lua_namespace {
|
||||||
typedef struct _swig_lua_namespace {
|
|
||||||
const char *name;
|
const char *name;
|
||||||
swig_lua_method *ns_methods;
|
swig_lua_method *ns_methods;
|
||||||
swig_lua_attribute *ns_attributes;
|
swig_lua_attribute *ns_attributes;
|
||||||
swig_lua_const_info *ns_constants;
|
swig_lua_const_info *ns_constants;
|
||||||
struct _swig_lua_class **ns_classes;
|
struct swig_lua_class **ns_classes;
|
||||||
struct _swig_lua_namespace **ns_namespaces;
|
struct swig_lua_namespace **ns_namespaces;
|
||||||
} swig_lua_namespace;
|
} swig_lua_namespace;
|
||||||
|
|
||||||
typedef struct _swig_lua_class {
|
typedef struct swig_lua_class {
|
||||||
const char *name; // Name that this class has in Lua
|
const char *name; /* Name that this class has in Lua */
|
||||||
const char *fqname; // Fully qualified name - Scope + class name
|
const char *fqname; /* Fully qualified name - Scope + class name */
|
||||||
swig_type_info **type;
|
swig_type_info **type;
|
||||||
lua_CFunction constructor;
|
lua_CFunction constructor;
|
||||||
void (*destructor)(void *);
|
void (*destructor)(void *);
|
||||||
swig_lua_method *methods;
|
swig_lua_method *methods;
|
||||||
swig_lua_attribute *attributes;
|
swig_lua_attribute *attributes;
|
||||||
swig_lua_namespace *cls_static;
|
swig_lua_namespace *cls_static;
|
||||||
struct _swig_lua_class **bases;
|
struct swig_lua_class **bases;
|
||||||
const char **base_names;
|
const char **base_names;
|
||||||
} swig_lua_class;
|
} swig_lua_class;
|
||||||
|
|
||||||
|
|
@ -249,7 +248,7 @@ typedef struct {
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
/* Special helper for member function pointers
|
/* Special helper for member function pointers
|
||||||
it gets the address, casts it, then dereferences it */
|
it gets the address, casts it, then dereferences it */
|
||||||
//#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a)))
|
/*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* storing/access of swig_module_info */
|
/* storing/access of swig_module_info */
|
||||||
|
|
@ -363,9 +362,9 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless
|
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
|
||||||
SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); // forward declaration
|
SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */
|
||||||
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration
|
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); /* forward declaration */
|
||||||
SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss);
|
SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss);
|
||||||
|
|
||||||
/* helper function - register namespace methods and attributes into namespace */
|
/* helper function - register namespace methods and attributes into namespace */
|
||||||
|
|
@ -396,7 +395,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *
|
||||||
*/
|
*/
|
||||||
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
|
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
|
||||||
{
|
{
|
||||||
// There must be module/namespace table at the top of the stack
|
/* There must be module/namespace table at the top of the stack */
|
||||||
assert(lua_istable(L,-1));
|
assert(lua_istable(L,-1));
|
||||||
|
|
||||||
swig_lua_class **classes = ns->ns_classes;
|
swig_lua_class **classes = ns->ns_classes;
|
||||||
|
|
@ -441,16 +440,16 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns,
|
||||||
|
|
||||||
lua_setmetatable(L,-2); /* set metatable */
|
lua_setmetatable(L,-2); /* set metatable */
|
||||||
|
|
||||||
// Register all functions, variables etc
|
/* Register all functions, variables etc */
|
||||||
SWIG_Lua_add_namespace_details(L,ns);
|
SWIG_Lua_add_namespace_details(L,ns);
|
||||||
// Register classes
|
/* Register classes */
|
||||||
SWIG_Lua_add_namespace_classes(L,ns);
|
SWIG_Lua_add_namespace_classes(L,ns);
|
||||||
|
|
||||||
swig_lua_namespace **sub_namespace = ns->ns_namespaces;
|
swig_lua_namespace **sub_namespace = ns->ns_namespaces;
|
||||||
if( sub_namespace != 0) {
|
if( sub_namespace != 0) {
|
||||||
while(*sub_namespace != 0) {
|
while(*sub_namespace != 0) {
|
||||||
SWIG_Lua_namespace_register(L, *sub_namespace, 1);
|
SWIG_Lua_namespace_register(L, *sub_namespace, 1);
|
||||||
lua_pop(L,1); // removing sub-namespace table
|
lua_pop(L,1); /* removing sub-namespace table */
|
||||||
sub_namespace++;
|
sub_namespace++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -462,7 +461,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns,
|
||||||
}
|
}
|
||||||
assert(lua_gettop(L) == begin+1);
|
assert(lua_gettop(L) == begin+1);
|
||||||
}
|
}
|
||||||
#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA
|
#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* global variable support code: classes
|
* global variable support code: classes
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -485,14 +484,14 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
|
||||||
} else\
|
} else\
|
||||||
valid = 1;
|
valid = 1;
|
||||||
|
|
||||||
#else // en elua .bases table doesn't exist. Use table from swig_lua_class
|
#else /* en elua .bases table doesn't exist. Use table from swig_lua_class */
|
||||||
|
|
||||||
#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\
|
#define SWIG_LUA_INIT_BASE_SEARCH(bases_count)\
|
||||||
swig_module_info *module=SWIG_GetModule(L);\
|
swig_module_info *module=SWIG_GetModule(L);\
|
||||||
swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\
|
swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\
|
||||||
const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\
|
const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\
|
||||||
bases_count = 0;\
|
bases_count = 0;\
|
||||||
for(;base_names[bases_count];bases_count++);// get length of bases
|
for(;base_names[bases_count];bases_count++);/* get length of bases */
|
||||||
|
|
||||||
#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\
|
#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\
|
||||||
swig_lua_class *base_class = bases[i];\
|
swig_lua_class *base_class = bases[i];\
|
||||||
|
|
@ -510,9 +509,9 @@ typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int
|
||||||
|
|
||||||
SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret)
|
SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret)
|
||||||
{
|
{
|
||||||
// first_arg - position of the object in stack. Everything that is above are arguments
|
/* first_arg - position of the object in stack. Everything that is above are arguments
|
||||||
// and is passed to every evocation of the func
|
* and is passed to every evocation of the func */
|
||||||
int last_arg = lua_gettop(L);// position of last argument
|
int last_arg = lua_gettop(L);/* position of last argument */
|
||||||
lua_getmetatable(L,first_arg);
|
lua_getmetatable(L,first_arg);
|
||||||
int original_metatable = last_arg + 1;
|
int original_metatable = last_arg + 1;
|
||||||
int bases_count;
|
int bases_count;
|
||||||
|
|
@ -523,39 +522,39 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int subcall_first_arg = lua_gettop(L) + 1;// Here a copy of first_arg and arguments begin
|
int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
|
||||||
int valid = 1;
|
int valid = 1;
|
||||||
for(j=first_arg;j<=last_arg;j++)
|
for(j=first_arg;j<=last_arg;j++)
|
||||||
lua_pushvalue(L,j);
|
lua_pushvalue(L,j);
|
||||||
int subcall_last_arg = lua_gettop(L);
|
int subcall_last_arg = lua_gettop(L);
|
||||||
swig_type_info *base_swig_type = 0;
|
swig_type_info *base_swig_type = 0;
|
||||||
|
|
||||||
// Trick: temporaly replacing original metatable
|
/* Trick: temporaly replacing original metatable
|
||||||
// with metatable for base class and call getter
|
* with metatable for base class and call getter */
|
||||||
for(i=0;i<bases_count;i++) {
|
for(i=0;i<bases_count;i++) {
|
||||||
SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid);
|
SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid);
|
||||||
if(!valid)
|
if(!valid)
|
||||||
continue;
|
continue;
|
||||||
assert(lua_isuserdata(L, subcall_first_arg));
|
assert(lua_isuserdata(L, subcall_first_arg));
|
||||||
assert(lua_istable(L,-1));
|
assert(lua_istable(L,-1));
|
||||||
lua_setmetatable(L,subcall_first_arg); // Set new metatable
|
lua_setmetatable(L,subcall_first_arg); /* Set new metatable */
|
||||||
assert(lua_gettop(L) == subcall_last_arg);
|
assert(lua_gettop(L) == subcall_last_arg);
|
||||||
result = func(L, base_swig_type,subcall_first_arg, ret); // Forward call
|
result = func(L, base_swig_type,subcall_first_arg, ret); /* Forward call */
|
||||||
if(ret) assert(lua_gettop(L) == subcall_last_arg + *ret); // TODO: REMOVE
|
if(ret) assert(lua_gettop(L) == subcall_last_arg + *ret); // TODO: REMOVE
|
||||||
if(result != SWIG_ERROR) {
|
if(result != SWIG_ERROR) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Return original metatable back
|
/* Return original metatable back */
|
||||||
lua_pushvalue(L,original_metatable);
|
lua_pushvalue(L,original_metatable);
|
||||||
lua_setmetatable(L,first_arg);
|
lua_setmetatable(L,first_arg);
|
||||||
// Clear - remove everything between last_arg and subcall_last_arg including
|
/* Clear - remove everything between last_arg and subcall_last_arg including */
|
||||||
const int to_remove = subcall_last_arg - last_arg;
|
const int to_remove = subcall_last_arg - last_arg;
|
||||||
for(j=0;j<to_remove;j++)
|
for(j=0;j<to_remove;j++)
|
||||||
lua_remove(L,last_arg+1);
|
lua_remove(L,last_arg+1);
|
||||||
if(ret) assert(lua_gettop(L) == last_arg + *ret); // TODO: REMOVE
|
if(ret) assert(lua_gettop(L) == last_arg + *ret); // TODO: REMOVE
|
||||||
} else {
|
} else {
|
||||||
// Remove everything after last_arg
|
/* Remove everything after last_arg */
|
||||||
lua_pop(L, lua_gettop(L) - last_arg);
|
lua_pop(L, lua_gettop(L) - last_arg);
|
||||||
}
|
}
|
||||||
if(ret) assert(lua_gettop(L) == last_arg + *ret);
|
if(ret) assert(lua_gettop(L) == last_arg + *ret);
|
||||||
|
|
@ -624,9 +623,9 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int fi
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
// Remove the metatable
|
/* Remove the metatable */
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
// Search in base classes
|
/* Search in base classes */
|
||||||
assert(lua_gettop(L) == substack_start + 2); // TODO: REMOVE
|
assert(lua_gettop(L) == substack_start + 2); // TODO: REMOVE
|
||||||
//printf("failed, searching bases\n"); // TODO: REMOVE
|
//printf("failed, searching bases\n"); // TODO: REMOVE
|
||||||
int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
|
int bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
|
||||||
|
|
@ -674,7 +673,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
||||||
assert(lua_isuserdata(L,substack_start+1)); /* just in case */
|
assert(lua_isuserdata(L,substack_start+1)); /* just in case */
|
||||||
lua_getmetatable(L,substack_start+1); /* get the meta table */
|
lua_getmetatable(L,substack_start+1); /* get the meta table */
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
if(ret) *ret = 0; // it is setter - number of return values is always 0
|
if(ret) *ret = 0; /* it is setter - number of return values is always 0 */
|
||||||
|
|
||||||
SWIG_Lua_get_table(L,".set"); /* find the .set table */
|
SWIG_Lua_get_table(L,".set"); /* find the .set table */
|
||||||
if (lua_istable(L,-1))
|
if (lua_istable(L,-1))
|
||||||
|
|
@ -708,11 +707,11 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
||||||
lua_remove(L,-2); /* stack tidy, remove metatable */
|
lua_remove(L,-2); /* stack tidy, remove metatable */
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
lua_pop(L,1); // remove value
|
lua_pop(L,1); /* remove value */
|
||||||
assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE
|
assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE
|
||||||
|
|
||||||
lua_pop(L,1); // remove metatable
|
lua_pop(L,1); /* remove metatable */
|
||||||
// Search among bases
|
/* Search among bases */
|
||||||
assert(lua_gettop(L) == first_arg+2); // TODO: REMOVE
|
assert(lua_gettop(L) == first_arg+2); // TODO: REMOVE
|
||||||
int bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
|
int bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
|
||||||
if(ret) assert(*ret == 0);
|
if(ret) assert(*ret == 0);
|
||||||
|
|
@ -847,7 +846,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) // In elua this is useless
|
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
|
||||||
/* helper add a variable to a registered class */
|
/* helper add a variable to a registered class */
|
||||||
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn)
|
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn)
|
||||||
{
|
{
|
||||||
|
|
@ -884,20 +883,20 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *
|
||||||
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class *clss)
|
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class *clss)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
// Add bases to .bases table
|
/* Add bases to .bases table */
|
||||||
SWIG_Lua_get_table(L,".bases");
|
SWIG_Lua_get_table(L,".bases");
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
int bases_count = 0;
|
int bases_count = 0;
|
||||||
for(i=0;clss->bases[i];i++)
|
for(i=0;clss->bases[i];i++)
|
||||||
{
|
{
|
||||||
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
|
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
|
||||||
// Base class must be already registered
|
/* Base class must be already registered */
|
||||||
assert(lua_istable(L,-1));
|
assert(lua_istable(L,-1));
|
||||||
lua_rawseti(L,-2,i+1); // In lua indexing starts from 1
|
lua_rawseti(L,-2,i+1); /* In lua indexing starts from 1 */
|
||||||
bases_count++;
|
bases_count++;
|
||||||
}
|
}
|
||||||
assert(lua_rawlen(L,-1) == bases_count);
|
assert(lua_rawlen(L,-1) == bases_count);
|
||||||
lua_pop(L,1); // remove .bases table
|
lua_pop(L,1); /* remove .bases table */
|
||||||
/* add attributes */
|
/* add attributes */
|
||||||
for(i=0;clss->attributes[i].name;i++){
|
for(i=0;clss->attributes[i].name;i++){
|
||||||
SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod);
|
SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod);
|
||||||
|
|
@ -958,7 +957,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
|
||||||
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
|
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
|
||||||
{
|
{
|
||||||
int begin = lua_gettop(L);
|
int begin = lua_gettop(L);
|
||||||
// if name already there (class is already registered) then do nothing
|
/* if name already there (class is already registered) then do nothing */
|
||||||
SWIG_Lua_get_class_registry(L); /* get the registry */
|
SWIG_Lua_get_class_registry(L); /* get the registry */
|
||||||
lua_pushstring(L,clss->fqname); /* get the name */
|
lua_pushstring(L,clss->fqname); /* get the name */
|
||||||
lua_rawget(L,-2);
|
lua_rawget(L,-2);
|
||||||
|
|
@ -967,14 +966,14 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
|
||||||
assert(lua_gettop(L)==begin);
|
assert(lua_gettop(L)==begin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lua_pop(L,2); // tidy stack
|
lua_pop(L,2); /* tidy stack */
|
||||||
// Recursively initialize all bases
|
/* Recursively initialize all bases */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(i=0;clss->bases[i];i++)
|
for(i=0;clss->bases[i];i++)
|
||||||
{
|
{
|
||||||
SWIG_Lua_class_register_instance(L,clss->bases[i]);
|
SWIG_Lua_class_register_instance(L,clss->bases[i]);
|
||||||
}
|
}
|
||||||
// Again, get registry and push name
|
/* Again, get registry and push name */
|
||||||
SWIG_Lua_get_class_registry(L); /* get the registry */
|
SWIG_Lua_get_class_registry(L); /* get the registry */
|
||||||
lua_pushstring(L,clss->fqname); /* get the name */
|
lua_pushstring(L,clss->fqname); /* get the name */
|
||||||
lua_newtable(L); /* create the metatable */
|
lua_newtable(L); /* create the metatable */
|
||||||
|
|
@ -1051,7 +1050,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
|
||||||
lua_pop(L,2);
|
lua_pop(L,2);
|
||||||
assert(lua_gettop(L) == begin);
|
assert(lua_gettop(L) == begin);
|
||||||
}
|
}
|
||||||
#endif // SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA
|
#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Class/structure conversion fns
|
* Class/structure conversion fns
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -86,16 +86,7 @@ Lua Options (available with -lua)\n\
|
||||||
Optional NUM is default value for MIN_OPT_LEVEL\n\
|
Optional NUM is default value for MIN_OPT_LEVEL\n\
|
||||||
-nomoduleglobal - Do not register the module name as a global variable \n\
|
-nomoduleglobal - Do not register the module name as a global variable \n\
|
||||||
but return the module table from calls to require.\n\
|
but return the module table from calls to require.\n\
|
||||||
-api-lvl-from NUM\n\
|
-swig3 - Disable support for old-style bindings name generation.\n\
|
||||||
- Force support for old-style bindings. All old-style bindings\n\
|
|
||||||
from NUM to current new-style bindings will be supported. For example,\n\
|
|
||||||
if current lua bindings API version is 10 and NUM==7 then SWIG will\n\
|
|
||||||
generate bindings compatible with lua bindings versions 7,8,9 and,\n\
|
|
||||||
of course current version of bindings, 10.\n\
|
|
||||||
API levels:\n\
|
|
||||||
2 - SWIG 2.*\n\
|
|
||||||
3 - SWIG 3.*\n\
|
|
||||||
Default NUM is 2.\n\
|
|
||||||
\n";
|
\n";
|
||||||
|
|
||||||
static int nomoduleglobal = 0;
|
static int nomoduleglobal = 0;
|
||||||
|
|
@ -186,12 +177,6 @@ public:
|
||||||
Delete(namespaces_hash);
|
Delete(namespaces_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NEW LANGUAGE NOTE:***********************************************
|
|
||||||
This is called to initalise the system & read any command line args
|
|
||||||
most of this is boilerplate code, except the command line args
|
|
||||||
which depends upon what args your code supports
|
|
||||||
NEW LANGUAGE NOTE:END *********************************************** */
|
|
||||||
|
|
||||||
bool strToInt(const char *string, int &value) {
|
bool strToInt(const char *string, int &value) {
|
||||||
long int tmp;
|
long int tmp;
|
||||||
char *p_end = 0;
|
char *p_end = 0;
|
||||||
|
|
@ -203,6 +188,12 @@ public:
|
||||||
value = tmp;
|
value = tmp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/* NEW LANGUAGE NOTE:***********************************************
|
||||||
|
This is called to initalise the system & read any command line args
|
||||||
|
most of this is boilerplate code, except the command line args
|
||||||
|
which depends upon what args your code supports
|
||||||
|
NEW LANGUAGE NOTE:END *********************************************** */
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------
|
/* ---------------------------------------------------------------------
|
||||||
* main()
|
* main()
|
||||||
*
|
*
|
||||||
|
|
@ -237,15 +228,9 @@ public:
|
||||||
Swig_mark_arg(i + 1);
|
Swig_mark_arg(i + 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-api-lvl-from") == 0) {
|
} else if (strcmp(argv[i], "-swig3") == 0) {
|
||||||
if (argv[i + 1]) {
|
Swig_mark_arg(i);
|
||||||
if (!strToInt(argv[i + 1], api_level))
|
api_level = 3;
|
||||||
Swig_arg_error();
|
|
||||||
Swig_mark_arg(i + 1);
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
Swig_arg_error();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -409,6 +394,10 @@ public:
|
||||||
return Language::importDirective(n);
|
return Language::importDirective(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* cDeclaration()
|
||||||
|
* It copies sym:name to lua:name to preserve it's original value
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
virtual int cDeclaration(Node *n) {
|
virtual int cDeclaration(Node *n) {
|
||||||
// class 'Language' is messing with symname in a really heavy way.
|
// class 'Language' is messing with symname in a really heavy way.
|
||||||
// Although documentation states that sym:name is a name in
|
// Although documentation states that sym:name is a name in
|
||||||
|
|
@ -463,7 +452,7 @@ public:
|
||||||
|
|
||||||
// Add method to the "methods" C array of given namespace/class
|
// Add method to the "methods" C array of given namespace/class
|
||||||
void registerMethod(String *nspace_or_class_name, Node *n) {
|
void registerMethod(String *nspace_or_class_name, Node *n) {
|
||||||
assert(n != 0);
|
assert(n);
|
||||||
Hash *nspaceHash = getNamespaceHash(nspace_or_class_name);
|
Hash *nspaceHash = getNamespaceHash(nspace_or_class_name);
|
||||||
String *s_ns_methods_tab = Getattr(nspaceHash, "methods");
|
String *s_ns_methods_tab = Getattr(nspaceHash, "methods");
|
||||||
String *wname = Getattr(n, "wrap:name");
|
String *wname = Getattr(n, "wrap:name");
|
||||||
|
|
@ -491,7 +480,7 @@ public:
|
||||||
String *name = Getattr(n, "name");
|
String *name = Getattr(n, "name");
|
||||||
String *iname = Getattr(n, "sym:name");
|
String *iname = Getattr(n, "sym:name");
|
||||||
String *target_name = Getattr(n, "lua:name");
|
String *target_name = Getattr(n, "lua:name");
|
||||||
assert(target_name != 0);
|
assert(target_name);
|
||||||
SwigType *d = Getattr(n, "type");
|
SwigType *d = Getattr(n, "type");
|
||||||
ParmList *l = Getattr(n, "parms");
|
ParmList *l = Getattr(n, "parms");
|
||||||
Parm *p;
|
Parm *p;
|
||||||
|
|
@ -516,7 +505,7 @@ public:
|
||||||
Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0");
|
Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0");
|
||||||
|
|
||||||
|
|
||||||
String *wname = symname_wrapper(iname);
|
String *wname = symnameWrapper(iname);
|
||||||
if (overname) {
|
if (overname) {
|
||||||
Append(wname, overname);
|
Append(wname, overname);
|
||||||
}
|
}
|
||||||
|
|
@ -830,8 +819,8 @@ public:
|
||||||
Wrapper *f = NewWrapper();
|
Wrapper *f = NewWrapper();
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
String *target_name = Getattr(n, "lua:name");
|
String *target_name = Getattr(n, "lua:name");
|
||||||
assert(target_name != 0);
|
assert(target_name);
|
||||||
String *wname = symname_wrapper(symname);
|
String *wname = symnameWrapper(symname);
|
||||||
|
|
||||||
//Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs);
|
//Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs);
|
||||||
|
|
||||||
|
|
@ -890,11 +879,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* variableWrapper()
|
* Add variable to the "attributes" (or "get"/"set" in
|
||||||
|
* case of elua_ltr) C arrays of given namespace or class
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
// Add variable to the "attributes" (or "get"/"set" in
|
|
||||||
// case of elua_ltr) C arrays of given namespace or class
|
|
||||||
void registerVariable(String *nspace_or_class_name, Node *n, const char *getAttrName, const char *setAttrName) {
|
void registerVariable(String *nspace_or_class_name, Node *n, const char *getAttrName, const char *setAttrName) {
|
||||||
String *unassignable = NewString("SWIG_Lua_set_immutable");
|
String *unassignable = NewString("SWIG_Lua_set_immutable");
|
||||||
String *getName = Getattr(n, getAttrName);
|
String *getName = Getattr(n, getAttrName);
|
||||||
|
|
@ -919,6 +906,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* variableWrapper()
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
virtual int variableWrapper(Node *n) {
|
virtual int variableWrapper(Node *n) {
|
||||||
/* NEW LANGUAGE NOTE:***********************************************
|
/* NEW LANGUAGE NOTE:***********************************************
|
||||||
Language::variableWrapper(n) will generate two wrapper fns
|
Language::variableWrapper(n) will generate two wrapper fns
|
||||||
|
|
@ -929,7 +920,7 @@ public:
|
||||||
NEW LANGUAGE NOTE:END *********************************************** */
|
NEW LANGUAGE NOTE:END *********************************************** */
|
||||||
// REPORT("variableWrapper", n);
|
// REPORT("variableWrapper", n);
|
||||||
String *target_name = Getattr(n, "lua:name");
|
String *target_name = Getattr(n, "lua:name");
|
||||||
assert(target_name != 0);
|
assert(target_name);
|
||||||
current[VARIABLE] = true;
|
current[VARIABLE] = true;
|
||||||
// let SWIG generate the wrappers
|
// let SWIG generate the wrappers
|
||||||
int result = Language::variableWrapper(n);
|
int result = Language::variableWrapper(n);
|
||||||
|
|
@ -940,12 +931,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* constantWrapper()
|
* Add constant to appropriate C array. constantRecord is an array record.
|
||||||
* ------------------------------------------------------------ */
|
|
||||||
|
|
||||||
/* Add constant to appropriate C array. constantRecord is an array record.
|
|
||||||
* Actually, in current implementation it is resolved consttab typemap
|
* Actually, in current implementation it is resolved consttab typemap
|
||||||
*/
|
* ------------------------------------------------------------ */
|
||||||
void registerConstant(String *nspace, String *constantRecord) {
|
void registerConstant(String *nspace, String *constantRecord) {
|
||||||
Hash *nspaceHash = getNamespaceHash(nspace);
|
Hash *nspaceHash = getNamespaceHash(nspace);
|
||||||
String *s_const_tab = 0;
|
String *s_const_tab = 0;
|
||||||
|
|
@ -955,17 +943,20 @@ public:
|
||||||
else
|
else
|
||||||
s_const_tab = Getattr(nspaceHash, "constants");
|
s_const_tab = Getattr(nspaceHash, "constants");
|
||||||
|
|
||||||
assert(s_const_tab != 0);
|
assert(s_const_tab);
|
||||||
Printf(s_const_tab, " %s,\n", constantRecord);
|
Printf(s_const_tab, " %s,\n", constantRecord);
|
||||||
|
|
||||||
if ((eluac_ltr || elua_ltr) && v2_compatibility) {
|
if ((eluac_ltr || elua_ltr) && v2_compatibility) {
|
||||||
s_const_tab = Getattr(nspaceHash, "constants");
|
s_const_tab = Getattr(nspaceHash, "constants");
|
||||||
assert(s_const_tab != 0);
|
assert(s_const_tab);
|
||||||
Printf(s_const_tab, " %s,\n", constantRecord);
|
Printf(s_const_tab, " %s,\n", constantRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* constantWrapper()
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
virtual int constantWrapper(Node *n) {
|
virtual int constantWrapper(Node *n) {
|
||||||
REPORT("constantWrapper", n);
|
REPORT("constantWrapper", n);
|
||||||
String *name = Getattr(n, "name");
|
String *name = Getattr(n, "name");
|
||||||
|
|
@ -990,7 +981,7 @@ public:
|
||||||
Setattr(n, "sym:name", target_name);
|
Setattr(n, "sym:name", target_name);
|
||||||
/* Special hook for member pointer */
|
/* Special hook for member pointer */
|
||||||
if (SwigType_type(type) == T_MPOINTER) {
|
if (SwigType_type(type) == T_MPOINTER) {
|
||||||
String *wname = symname_wrapper(iname);
|
String *wname = symnameWrapper(iname);
|
||||||
Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value);
|
Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value);
|
||||||
value = Char(wname);
|
value = Char(wname);
|
||||||
}
|
}
|
||||||
|
|
@ -1123,28 +1114,29 @@ public:
|
||||||
return Language::classDeclaration(n);
|
return Language::classDeclaration(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
|
||||||
* classHandler()
|
|
||||||
* ------------------------------------------------------------ */
|
|
||||||
|
|
||||||
/* Helper function that adds record to appropriate
|
/* ------------------------------------------------------------
|
||||||
|
* Helper function that adds record to appropriate
|
||||||
* C arrays
|
* C arrays
|
||||||
*/
|
* ------------------------------------------------------------ */
|
||||||
void registerClass(String *scope, Node *n) {
|
void registerClass(String *scope, Node *n) {
|
||||||
String *wrap_class = Getattr(n,"wrap:class_name");
|
String *wrap_class = Getattr(n,"wrap:class_name");
|
||||||
assert(wrap_class != 0);
|
assert(wrap_class);
|
||||||
Hash *nspaceHash = getNamespaceHash(scope);
|
Hash *nspaceHash = getNamespaceHash(scope);
|
||||||
String *ns_classes = Getattr(nspaceHash, "classes");
|
String *ns_classes = Getattr(nspaceHash, "classes");
|
||||||
Printv(ns_classes, "&", wrap_class, ",\n", NIL);
|
Printv(ns_classes, "&", wrap_class, ",\n", NIL);
|
||||||
if (elua_ltr || eluac_ltr) {
|
if (elua_ltr || eluac_ltr) {
|
||||||
String *ns_methods = Getattr(nspaceHash, "methods");
|
String *ns_methods = Getattr(nspaceHash, "methods");
|
||||||
Hash *class_hash = getNamespaceHash(class_fq_symname);
|
Hash *class_hash = getNamespaceHash(class_fq_symname);
|
||||||
assert(class_hash != 0);
|
assert(class_hash);
|
||||||
String *cls_methods = Getattr(class_hash, "methods:name");
|
String *cls_methods = Getattr(class_hash, "methods:name");
|
||||||
assert(cls_methods != 0);
|
assert(cls_methods);
|
||||||
Printv(ns_methods, tab4, "{LSTRKEY(\"", class_symname, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL);
|
Printv(ns_methods, tab4, "{LSTRKEY(\"", class_symname, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* classHandler()
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
virtual int classHandler(Node *n) {
|
virtual int classHandler(Node *n) {
|
||||||
//REPORT("classHandler", n);
|
//REPORT("classHandler", n);
|
||||||
|
|
||||||
|
|
@ -1174,7 +1166,7 @@ public:
|
||||||
else
|
else
|
||||||
class_fq_symname = NewStringf("%s.%s", nspace, class_symname);
|
class_fq_symname = NewStringf("%s.%s", nspace, class_symname);
|
||||||
|
|
||||||
assert(class_fq_symname != 0);
|
assert(class_fq_symname);
|
||||||
mangled_class_fq_symname = Swig_name_mangle(class_fq_symname);
|
mangled_class_fq_symname = Swig_name_mangle(class_fq_symname);
|
||||||
|
|
||||||
SwigType *t = Copy(Getattr(n, "name"));
|
SwigType *t = Copy(Getattr(n, "name"));
|
||||||
|
|
@ -1212,7 +1204,7 @@ public:
|
||||||
// and capital letter are forbiden to use in C++. So, under know circumstances could our class contain
|
// and capital letter are forbiden to use in C++. So, under know circumstances could our class contain
|
||||||
// any member or subclass with name "__Static". Thus, never any name clash.
|
// any member or subclass with name "__Static". Thus, never any name clash.
|
||||||
Hash *instance_cls = getNamespaceHash(class_fq_symname, false);
|
Hash *instance_cls = getNamespaceHash(class_fq_symname, false);
|
||||||
assert(instance_cls != 0);
|
assert(instance_cls);
|
||||||
String *s_attr_tab_name = Getattr(instance_cls, "attributes:name");
|
String *s_attr_tab_name = Getattr(instance_cls, "attributes:name");
|
||||||
String *s_methods_tab_name = Getattr(instance_cls, "methods:name");
|
String *s_methods_tab_name = Getattr(instance_cls, "methods:name");
|
||||||
Setattr(instance_cls, "lua:no_namespaces", "1");
|
Setattr(instance_cls, "lua:no_namespaces", "1");
|
||||||
|
|
@ -1225,7 +1217,7 @@ public:
|
||||||
|
|
||||||
class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR);
|
class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR);
|
||||||
Hash *static_cls = getNamespaceHash(class_static_nspace, false);
|
Hash *static_cls = getNamespaceHash(class_static_nspace, false);
|
||||||
assert(static_cls != 0);
|
assert(static_cls);
|
||||||
Setattr(static_cls, "lua:no_namespaces", "1");
|
Setattr(static_cls, "lua:no_namespaces", "1");
|
||||||
Setattr(static_cls, "lua:class_static", "1");
|
Setattr(static_cls, "lua:class_static", "1");
|
||||||
|
|
||||||
|
|
@ -1296,18 +1288,18 @@ public:
|
||||||
constructor_name = constructor_proxy_name;
|
constructor_name = constructor_proxy_name;
|
||||||
if (elua_ltr) {
|
if (elua_ltr) {
|
||||||
String *static_cls_metatable_tab = Getattr(static_cls, "metatable");
|
String *static_cls_metatable_tab = Getattr(static_cls, "metatable");
|
||||||
assert(static_cls_metatable_tab != 0);
|
assert(static_cls_metatable_tab);
|
||||||
Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name);
|
Printf(static_cls_metatable_tab, " {LSTRKEY(\"__call\"), LFUNCVAL(%s)},\n", constructor_name);
|
||||||
} else if (eluac_ltr) {
|
} else if (eluac_ltr) {
|
||||||
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
||||||
assert(ns_methods_tab != 0);
|
assert(ns_methods_tab);
|
||||||
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL);
|
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "new_", class_symname, "\")", ", LFUNCVAL(", constructor_name, ")", "},\n", NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (have_destructor) {
|
if (have_destructor) {
|
||||||
if (eluac_ltr) {
|
if (eluac_ltr) {
|
||||||
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
String *ns_methods_tab = Getattr(nspaceHash, "methods");
|
||||||
assert(ns_methods_tab != 0);
|
assert(ns_methods_tab);
|
||||||
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL);
|
Printv(ns_methods_tab, tab4, "{LSTRKEY(\"", "free_", mangled_class_fq_symname, "\")", ", LFUNCVAL(", destructor_name, ")", "},\n", NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1599,10 +1591,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is to convert the string of Lua code into a proper string, which can then be
|
/* -----------------------------------------------------------------------------
|
||||||
emitted into the C/C++ code.
|
* EscapeCode()
|
||||||
Basically is is a lot of search & replacing of odd sequences
|
* This is to convert the string of Lua code into a proper string, which can then be
|
||||||
*/
|
* emitted into the C/C++ code.
|
||||||
|
* Basically is is a lot of search & replacing of odd sequences
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
void EscapeCode(String *str) {
|
void EscapeCode(String *str) {
|
||||||
//Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str);
|
//Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str);
|
||||||
Chop(str); // trim
|
Chop(str); // trim
|
||||||
|
|
@ -1612,18 +1606,22 @@ public:
|
||||||
//Printf(f_runtime,"/* hacked luacode:[[[\n%s\n]]]\n*/\n",str);
|
//Printf(f_runtime,"/* hacked luacode:[[[\n%s\n]]]\n*/\n",str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Each namespace can be described with hash that stores C arrays
|
/* -----------------------------------------------------------------------------
|
||||||
where members of the namespace should be added. All these hashes are stored
|
* getNamespaceHash()
|
||||||
inside namespaces_hash.
|
* Each namespace can be described with hash that stores C arrays
|
||||||
nspace could be NULL (NSPACE_TODO), that means functions and variables and classes
|
* where members of the namespace should be added. All these hashes are stored
|
||||||
that are not in any namespace (this is default for SWIG unless %nspace feature is used)
|
* inside namespaces_hash.
|
||||||
You can later set some attributes that will affect behaviour of functions that use this hash:
|
* nspace could be NULL (NSPACE_TODO), that means functions and variables and classes
|
||||||
"lua:no_namespaces" will disable "namespaces" array.
|
* that are not in any namespace (this is default for SWIG unless %nspace feature is used)
|
||||||
"lua:no_classes" will disable "classes" array.
|
* You can later set some attributes that will affect behaviour of functions that use this hash:
|
||||||
For every component ("attributes", "methods", etc) there are subcomponents:
|
* "lua:no_namespaces" will disable "namespaces" array.
|
||||||
* XXX:name - name of the C array that stores data for component
|
* "lua:no_classes" will disable "classes" array.
|
||||||
* XXX:decl - statement with forward declaration of this array;
|
* For every component ("attributes", "methods", etc) there are subcomponents:
|
||||||
*/
|
* XXX:name - name of the C array that stores data for component
|
||||||
|
* XXX:decl - statement with forward declaration of this array;
|
||||||
|
* Namespace could be automatically registered to it's parent if 'reg' == true. It can be done
|
||||||
|
* only at first call (a.k.a when nspace is created).
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
Hash *getNamespaceHash(String *nspace, bool reg = true) {
|
Hash *getNamespaceHash(String *nspace, bool reg = true) {
|
||||||
Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : "");
|
Hash *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : "");
|
||||||
if (nspace_hash != 0)
|
if (nspace_hash != 0)
|
||||||
|
|
@ -1770,17 +1768,19 @@ public:
|
||||||
return nspace_hash;
|
return nspace_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Functions add end markers {0,0,...,0} to all arrays, prints them to
|
/* -----------------------------------------------------------------------------
|
||||||
|
* closeNamespaceHash()
|
||||||
|
* Functions add end markers {0,0,...,0} to all arrays, prints them to
|
||||||
* output and marks hash as closed (lua:closed). Consequent attempts to
|
* output and marks hash as closed (lua:closed). Consequent attempts to
|
||||||
* close same hash will result in error
|
* close same hash will result in error
|
||||||
* closeNamespaceHash DOES NOT print structure that describes namespace, it only
|
* closeNamespaceHash DOES NOT print structure that describes namespace, it only
|
||||||
* prints array. You can use printNamespaceDefinition to print structure.
|
* prints array. You can use printNamespaceDefinition to print structure.
|
||||||
* if "lua:no_namespaces" is set, then array for "namespaces" won't be printed
|
* if "lua:no_namespaces" is set, then array for "namespaces" won't be printed
|
||||||
* if "lua:no_classes" is set, then array for "classes" won't be printed
|
* if "lua:no_classes" is set, then array for "classes" won't be printed
|
||||||
* */
|
* ----------------------------------------------------------------------------- */
|
||||||
void closeNamespaceHash(String *nspace, File *output) {
|
void closeNamespaceHash(String *nspace, File *output) {
|
||||||
Hash *nspace_hash = Getattr(namespaces_hash, nspace);
|
Hash *nspace_hash = Getattr(namespaces_hash, nspace);
|
||||||
assert(nspace_hash != 0);
|
assert(nspace_hash);
|
||||||
assert(Getattr(nspace_hash, "lua:closed") == 0);
|
assert(Getattr(nspace_hash, "lua:closed") == 0);
|
||||||
|
|
||||||
Setattr(nspace_hash, "lua:closed", "1");
|
Setattr(nspace_hash, "lua:closed", "1");
|
||||||
|
|
@ -1836,26 +1836,26 @@ public:
|
||||||
Printv(output, set_tab, NIL);
|
Printv(output, set_tab, NIL);
|
||||||
|
|
||||||
String *metatable_tab = Getattr(nspace_hash, "metatable");
|
String *metatable_tab = Getattr(nspace_hash, "metatable");
|
||||||
assert(metatable_tab != 0);
|
assert(metatable_tab);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\"__index\"), LFUNCVAL(SWIG_Lua_namespace_get)},\n", NIL);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\"__newindex\"), LFUNCVAL(SWIG_Lua_namespace_set)},\n", NIL);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".get\"), LROVAL(", get_tab_name, ")},\n", NIL);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL);
|
||||||
if (Getattr(nspace_hash, "lua:class_instance")) {
|
if (Getattr(nspace_hash, "lua:class_instance")) {
|
||||||
String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash");
|
String *static_cls = Getattr(nspace_hash, "lua:class_instance:static_hash");
|
||||||
assert(static_cls != 0);
|
assert(static_cls);
|
||||||
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
|
// static_cls is swig_lua_namespace. This structure can't be use with eLua(LTR)
|
||||||
// Instead structure describing its methods isused
|
// Instead structure describing its methods isused
|
||||||
String *static_cls_cname = Getattr(static_cls, "methods:name");
|
String *static_cls_cname = Getattr(static_cls, "methods:name");
|
||||||
assert(static_cls_cname != 0);
|
assert(static_cls_cname);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".static\"), LROVAL(", static_cls_cname, ")},\n", NIL);
|
||||||
// Put forward declaration of this array
|
// Put forward declaration of this array
|
||||||
Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL);
|
Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL);
|
||||||
} else if (Getattr(nspace_hash, "lua:class_static")) {
|
} else if (Getattr(nspace_hash, "lua:class_static")) {
|
||||||
Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash");
|
Hash *instance_cls = Getattr(nspace_hash, "lua:class_static:instance_hash");
|
||||||
assert(instance_cls != 0);
|
assert(instance_cls);
|
||||||
String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name");
|
String *instance_cls_metatable_name = Getattr(instance_cls, "metatable:name");
|
||||||
assert(instance_cls_metatable_name != 0);
|
assert(instance_cls_metatable_name);
|
||||||
Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL);
|
Printv(metatable_tab, tab4, "{LSTRKEY(\".instance\"), LROVAL(", instance_cls_metatable_name, ")},\n", NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1868,7 +1868,11 @@ public:
|
||||||
static int compareByLen(const DOH *f, const DOH *s) {
|
static int compareByLen(const DOH *f, const DOH *s) {
|
||||||
return Len(s) - Len(f);
|
return Len(s) - Len(f);
|
||||||
}
|
}
|
||||||
// Recursively close all non-closed namespaces. Prints data to dataOutput,
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* closeNamespaceHash()
|
||||||
|
* Recursively close all non-closed namespaces. Prints data to dataOutput.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
void closeNamespaces(File *dataOutput) {
|
void closeNamespaces(File *dataOutput) {
|
||||||
// Special handling for empty module.
|
// Special handling for empty module.
|
||||||
if (Getattr(namespaces_hash, "") == 0) {
|
if (Getattr(namespaces_hash, "") == 0) {
|
||||||
|
|
@ -1894,22 +1898,26 @@ public:
|
||||||
name = module;
|
name = module;
|
||||||
else
|
else
|
||||||
name = Getattr(nspace, "name");
|
name = Getattr(nspace, "name");
|
||||||
assert(name != 0);
|
assert(name);
|
||||||
printNamespaceDefinition(key, name, dataOutput);
|
printNamespaceDefinition(key, name, dataOutput);
|
||||||
}
|
}
|
||||||
Delete(to_close);
|
Delete(to_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function prints to output a definition of namespace in
|
/* -----------------------------------------------------------------------------
|
||||||
// form of swig_lua_namespace: { attr_array, methods_array, ... , namespaces_array }.
|
* printNamespaceDefinition()
|
||||||
// You can call this function as many times as necessary.
|
* This function prints to output a definition of namespace in
|
||||||
// 'name' is a user-visible name that this namespace will have in Lua. It shouldn't
|
* form
|
||||||
// be fully qualified name, just it's own name.
|
* swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array };
|
||||||
|
* You can call this function as many times as necessary.
|
||||||
|
* 'name' is a user-visible name that this namespace will have in Lua. It shouldn't
|
||||||
|
* be fully qualified name, just it's own name.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
void printNamespaceDefinition(String *nspace, String *name, File *output) {
|
void printNamespaceDefinition(String *nspace, String *name, File *output) {
|
||||||
Hash *nspace_hash = getNamespaceHash(nspace, false);
|
Hash *nspace_hash = getNamespaceHash(nspace, false);
|
||||||
|
|
||||||
String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace
|
String *cname = Getattr(nspace_hash, "cname"); // cname - name of the C structure that describes namespace
|
||||||
assert(cname != 0);
|
assert(cname);
|
||||||
Printv(output, "static swig_lua_namespace ", cname, " = ", NIL);
|
Printv(output, "static swig_lua_namespace ", cname, " = ", NIL);
|
||||||
|
|
||||||
String *null_string = NewString("0");
|
String *null_string = NewString("0");
|
||||||
|
|
@ -1931,12 +1939,15 @@ public:
|
||||||
Delete(null_string);
|
Delete(null_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function determines actual namespace/scope where any symbol at the
|
/* -----------------------------------------------------------------------------
|
||||||
// current moment should be placed. It looks at the 'current' array
|
* luaCurrentSymbolNSpace()
|
||||||
// and depending on where are we - static class member/function,
|
* This function determines actual namespace/scope where any symbol at the
|
||||||
// instance class member/function or just global functions decides
|
* current moment should be placed. It looks at the 'current' array
|
||||||
// where symbol should be put.
|
* and depending on where are we - static class member/function,
|
||||||
// The namespace/scope doesn't depend from symbol, only from 'current'
|
* instance class member/function or just global functions decides
|
||||||
|
* where symbol should be put.
|
||||||
|
* The namespace/scope doesn't depend from symbol, only from 'current'
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
String *luaCurrentSymbolNSpace() {
|
String *luaCurrentSymbolNSpace() {
|
||||||
String *scope = 0;
|
String *scope = 0;
|
||||||
// If ouside class, than NSpace is used.
|
// If ouside class, than NSpace is used.
|
||||||
|
|
@ -1954,12 +1965,15 @@ public:
|
||||||
} else { // Friend functions are handled this way
|
} else { // Friend functions are handled this way
|
||||||
scope = class_static_nspace;
|
scope = class_static_nspace;
|
||||||
}
|
}
|
||||||
assert(scope != 0);
|
assert(scope);
|
||||||
}
|
}
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol
|
/* -----------------------------------------------------------------------------
|
||||||
|
* luaAddSymbol()
|
||||||
|
* Our implementation of addSymbol. Determines scope correctly, then calls Language::addSymbol
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
int luaAddSymbol(const String *s, const Node *n) {
|
int luaAddSymbol(const String *s, const Node *n) {
|
||||||
String *scope = luaCurrentSymbolNSpace();
|
String *scope = luaCurrentSymbolNSpace();
|
||||||
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
||||||
|
|
@ -1969,7 +1983,10 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol
|
/* -----------------------------------------------------------------------------
|
||||||
|
* luaAddSymbol()
|
||||||
|
* Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
|
int luaAddSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
|
||||||
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
||||||
int result = Language::addSymbol(s, n, scope);
|
int result = Language::addSymbol(s, n, scope);
|
||||||
|
|
@ -1978,15 +1995,14 @@ public:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function creates fully qualified name of given symbol. Current NSpace and current class
|
/* -----------------------------------------------------------------------------
|
||||||
// are used
|
* fullyQualifiedName()
|
||||||
String *fully_qualified_name(const_String_or_char_ptr name) {
|
* Function creates fully qualified name of given symbol. The scope is deremined
|
||||||
assert(name != 0);
|
* automatically based on luaCurrentSymbolNSpace()
|
||||||
String *scope = 0;
|
* ----------------------------------------------------------------------------- */
|
||||||
if (getCurrentClass())
|
String *fullyQualifiedName(const_String_or_char_ptr name) {
|
||||||
scope = class_fq_symname;
|
assert(name);
|
||||||
else
|
String *scope = luaCurrentSymbolNSpace();
|
||||||
scope = getNSpace();
|
|
||||||
|
|
||||||
String *fqname = 0;
|
String *fqname = 0;
|
||||||
if (scope)
|
if (scope)
|
||||||
|
|
@ -1997,10 +2013,13 @@ public:
|
||||||
return fqname;
|
return fqname;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input: symname
|
/* -----------------------------------------------------------------------------
|
||||||
// Output - wrapper around fully qualified form of symname
|
* symnameWrapper()
|
||||||
String *symname_wrapper(String *symname) {
|
* Input: symname
|
||||||
String *fqname = fully_qualified_name(symname);
|
* Output - Swig_name_wrapper around fully qualified form of symname
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
String *symnameWrapper(String *symname) {
|
||||||
|
String *fqname = fullyQualifiedName(symname);
|
||||||
String *wname = Swig_name_wrapper(fqname);
|
String *wname = Swig_name_wrapper(fqname);
|
||||||
Delete(fqname);
|
Delete(fqname);
|
||||||
return wname;
|
return wname;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue