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_STRING(B, C) LSTRKEY(B), LSTRVAL(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_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
|
||||
#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)
|
||||
typedef const LUA_REG_TYPE swig_lua_method;
|
||||
typedef const LUA_REG_TYPE swig_lua_const_info;
|
||||
#else // Normal lua
|
||||
#else /* Normal lua */
|
||||
typedef luaL_Reg swig_lua_method;
|
||||
|
||||
/* Constant information structure */
|
||||
|
|
@ -159,28 +159,27 @@ typedef struct {
|
|||
} swig_lua_attribute;
|
||||
|
||||
|
||||
struct _swig_lua_class;
|
||||
// Can be used to create namespaces. Currently used to
|
||||
// wrap class static methods/variables/constants
|
||||
typedef struct _swig_lua_namespace {
|
||||
struct swig_lua_class;
|
||||
/* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */
|
||||
typedef struct swig_lua_namespace {
|
||||
const char *name;
|
||||
swig_lua_method *ns_methods;
|
||||
swig_lua_attribute *ns_attributes;
|
||||
swig_lua_const_info *ns_constants;
|
||||
struct _swig_lua_class **ns_classes;
|
||||
struct _swig_lua_namespace **ns_namespaces;
|
||||
struct swig_lua_class **ns_classes;
|
||||
struct swig_lua_namespace **ns_namespaces;
|
||||
} swig_lua_namespace;
|
||||
|
||||
typedef struct _swig_lua_class {
|
||||
const char *name; // Name that this class has in Lua
|
||||
const char *fqname; // Fully qualified name - Scope + class name
|
||||
typedef struct swig_lua_class {
|
||||
const char *name; /* Name that this class has in Lua */
|
||||
const char *fqname; /* Fully qualified name - Scope + class name */
|
||||
swig_type_info **type;
|
||||
lua_CFunction constructor;
|
||||
void (*destructor)(void *);
|
||||
swig_lua_method *methods;
|
||||
swig_lua_attribute *attributes;
|
||||
swig_lua_namespace *cls_static;
|
||||
struct _swig_lua_class **bases;
|
||||
struct swig_lua_class **bases;
|
||||
const char **base_names;
|
||||
} swig_lua_class;
|
||||
|
||||
|
|
@ -249,7 +248,7 @@ typedef struct {
|
|||
#ifdef __cplusplus
|
||||
/* Special helper for member function pointers
|
||||
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
|
||||
|
||||
/* storing/access of swig_module_info */
|
||||
|
|
@ -363,9 +362,9 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#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_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration
|
||||
#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_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);
|
||||
|
||||
/* 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)
|
||||
{
|
||||
// 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));
|
||||
|
||||
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 */
|
||||
|
||||
// Register all functions, variables etc
|
||||
/* Register all functions, variables etc */
|
||||
SWIG_Lua_add_namespace_details(L,ns);
|
||||
// Register classes
|
||||
/* Register classes */
|
||||
SWIG_Lua_add_namespace_classes(L,ns);
|
||||
|
||||
swig_lua_namespace **sub_namespace = ns->ns_namespaces;
|
||||
if( sub_namespace != 0) {
|
||||
while(*sub_namespace != 0) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
|
@ -462,7 +461,7 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns,
|
|||
}
|
||||
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
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -485,14 +484,14 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
|
|||
} else\
|
||||
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)\
|
||||
swig_module_info *module=SWIG_GetModule(L);\
|
||||
swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;\
|
||||
const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;\
|
||||
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)\
|
||||
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)
|
||||
{
|
||||
// first_arg - position of the object in stack. Everything that is above are arguments
|
||||
// and is passed to every evocation of the func
|
||||
int last_arg = lua_gettop(L);// position of last argument
|
||||
/* first_arg - position of the object in stack. Everything that is above are arguments
|
||||
* and is passed to every evocation of the func */
|
||||
int last_arg = lua_gettop(L);/* position of last argument */
|
||||
lua_getmetatable(L,first_arg);
|
||||
int original_metatable = last_arg + 1;
|
||||
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 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;
|
||||
for(j=first_arg;j<=last_arg;j++)
|
||||
lua_pushvalue(L,j);
|
||||
int subcall_last_arg = lua_gettop(L);
|
||||
swig_type_info *base_swig_type = 0;
|
||||
|
||||
// Trick: temporaly replacing original metatable
|
||||
// with metatable for base class and call getter
|
||||
/* Trick: temporaly replacing original metatable
|
||||
* with metatable for base class and call getter */
|
||||
for(i=0;i<bases_count;i++) {
|
||||
SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type,valid);
|
||||
if(!valid)
|
||||
continue;
|
||||
assert(lua_isuserdata(L, subcall_first_arg));
|
||||
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);
|
||||
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(result != SWIG_ERROR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Return original metatable back
|
||||
/* Return original metatable back */
|
||||
lua_pushvalue(L,original_metatable);
|
||||
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;
|
||||
for(j=0;j<to_remove;j++)
|
||||
lua_remove(L,last_arg+1);
|
||||
if(ret) assert(lua_gettop(L) == last_arg + *ret); // TODO: REMOVE
|
||||
} else {
|
||||
// Remove everything after last_arg
|
||||
/* Remove everything after last_arg */
|
||||
lua_pop(L, lua_gettop(L) - last_arg);
|
||||
}
|
||||
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;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
// Remove the metatable
|
||||
/* Remove the metatable */
|
||||
lua_pop(L,1);
|
||||
// Search in base classes
|
||||
/* Search in base classes */
|
||||
assert(lua_gettop(L) == substack_start + 2); // 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);
|
||||
|
|
@ -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 */
|
||||
lua_getmetatable(L,substack_start+1); /* get the meta table */
|
||||
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 */
|
||||
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 */
|
||||
return SWIG_OK;
|
||||
}
|
||||
lua_pop(L,1); // remove value
|
||||
lua_pop(L,1); /* remove value */
|
||||
assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE
|
||||
|
||||
lua_pop(L,1); // remove metatable
|
||||
// Search among bases
|
||||
lua_pop(L,1); /* remove metatable */
|
||||
/* Search among bases */
|
||||
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);
|
||||
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 */
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
// Add bases to .bases table
|
||||
/* Add bases to .bases table */
|
||||
SWIG_Lua_get_table(L,".bases");
|
||||
assert(lua_istable(L,-1)); /* just in case */
|
||||
int bases_count = 0;
|
||||
for(i=0;clss->bases[i];i++)
|
||||
{
|
||||
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));
|
||||
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++;
|
||||
}
|
||||
assert(lua_rawlen(L,-1) == bases_count);
|
||||
lua_pop(L,1); // remove .bases table
|
||||
lua_pop(L,1); /* remove .bases table */
|
||||
/* add attributes */
|
||||
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);
|
||||
|
|
@ -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)
|
||||
{
|
||||
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 */
|
||||
lua_pushstring(L,clss->fqname); /* get the name */
|
||||
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);
|
||||
return;
|
||||
}
|
||||
lua_pop(L,2); // tidy stack
|
||||
// Recursively initialize all bases
|
||||
lua_pop(L,2); /* tidy stack */
|
||||
/* Recursively initialize all bases */
|
||||
int i = 0;
|
||||
for(i=0;clss->bases[i];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 */
|
||||
lua_pushstring(L,clss->fqname); /* get the name */
|
||||
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);
|
||||
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
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -86,16 +86,7 @@ Lua Options (available with -lua)\n\
|
|||
Optional NUM is default value for MIN_OPT_LEVEL\n\
|
||||
-nomoduleglobal - Do not register the module name as a global variable \n\
|
||||
but return the module table from calls to require.\n\
|
||||
-api-lvl-from NUM\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\
|
||||
-swig3 - Disable support for old-style bindings name generation.\n\
|
||||
\n";
|
||||
|
||||
static int nomoduleglobal = 0;
|
||||
|
|
@ -186,12 +177,6 @@ public:
|
|||
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) {
|
||||
long int tmp;
|
||||
char *p_end = 0;
|
||||
|
|
@ -203,6 +188,12 @@ public:
|
|||
value = tmp;
|
||||
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()
|
||||
*
|
||||
|
|
@ -237,15 +228,9 @@ public:
|
|||
Swig_mark_arg(i + 1);
|
||||
i++;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-api-lvl-from") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
if (!strToInt(argv[i + 1], api_level))
|
||||
Swig_arg_error();
|
||||
Swig_mark_arg(i + 1);
|
||||
i++;
|
||||
} else {
|
||||
Swig_arg_error();
|
||||
}
|
||||
} else if (strcmp(argv[i], "-swig3") == 0) {
|
||||
Swig_mark_arg(i);
|
||||
api_level = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -409,6 +394,10 @@ public:
|
|||
return Language::importDirective(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* cDeclaration()
|
||||
* It copies sym:name to lua:name to preserve it's original value
|
||||
* ------------------------------------------------------------ */
|
||||
virtual int cDeclaration(Node *n) {
|
||||
// class 'Language' is messing with symname in a really heavy way.
|
||||
// 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
|
||||
void registerMethod(String *nspace_or_class_name, Node *n) {
|
||||
assert(n != 0);
|
||||
assert(n);
|
||||
Hash *nspaceHash = getNamespaceHash(nspace_or_class_name);
|
||||
String *s_ns_methods_tab = Getattr(nspaceHash, "methods");
|
||||
String *wname = Getattr(n, "wrap:name");
|
||||
|
|
@ -491,7 +480,7 @@ public:
|
|||
String *name = Getattr(n, "name");
|
||||
String *iname = Getattr(n, "sym:name");
|
||||
String *target_name = Getattr(n, "lua:name");
|
||||
assert(target_name != 0);
|
||||
assert(target_name);
|
||||
SwigType *d = Getattr(n, "type");
|
||||
ParmList *l = Getattr(n, "parms");
|
||||
Parm *p;
|
||||
|
|
@ -516,7 +505,7 @@ public:
|
|||
Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = 0");
|
||||
|
||||
|
||||
String *wname = symname_wrapper(iname);
|
||||
String *wname = symnameWrapper(iname);
|
||||
if (overname) {
|
||||
Append(wname, overname);
|
||||
}
|
||||
|
|
@ -830,8 +819,8 @@ public:
|
|||
Wrapper *f = NewWrapper();
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
String *target_name = Getattr(n, "lua:name");
|
||||
assert(target_name != 0);
|
||||
String *wname = symname_wrapper(symname);
|
||||
assert(target_name);
|
||||
String *wname = symnameWrapper(symname);
|
||||
|
||||
//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) {
|
||||
String *unassignable = NewString("SWIG_Lua_set_immutable");
|
||||
String *getName = Getattr(n, getAttrName);
|
||||
|
|
@ -919,6 +906,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* variableWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
virtual int variableWrapper(Node *n) {
|
||||
/* NEW LANGUAGE NOTE:***********************************************
|
||||
Language::variableWrapper(n) will generate two wrapper fns
|
||||
|
|
@ -929,7 +920,7 @@ public:
|
|||
NEW LANGUAGE NOTE:END *********************************************** */
|
||||
// REPORT("variableWrapper", n);
|
||||
String *target_name = Getattr(n, "lua:name");
|
||||
assert(target_name != 0);
|
||||
assert(target_name);
|
||||
current[VARIABLE] = true;
|
||||
// let SWIG generate the wrappers
|
||||
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
|
||||
*/
|
||||
* ------------------------------------------------------------ */
|
||||
void registerConstant(String *nspace, String *constantRecord) {
|
||||
Hash *nspaceHash = getNamespaceHash(nspace);
|
||||
String *s_const_tab = 0;
|
||||
|
|
@ -955,17 +943,20 @@ public:
|
|||
else
|
||||
s_const_tab = Getattr(nspaceHash, "constants");
|
||||
|
||||
assert(s_const_tab != 0);
|
||||
assert(s_const_tab);
|
||||
Printf(s_const_tab, " %s,\n", constantRecord);
|
||||
|
||||
if ((eluac_ltr || elua_ltr) && v2_compatibility) {
|
||||
s_const_tab = Getattr(nspaceHash, "constants");
|
||||
assert(s_const_tab != 0);
|
||||
assert(s_const_tab);
|
||||
Printf(s_const_tab, " %s,\n", constantRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* constantWrapper()
|
||||
* ------------------------------------------------------------ */
|
||||
virtual int constantWrapper(Node *n) {
|
||||
REPORT("constantWrapper", n);
|
||||
String *name = Getattr(n, "name");
|
||||
|
|
@ -990,7 +981,7 @@ public:
|
|||
Setattr(n, "sym:name", target_name);
|
||||
/* Special hook for member pointer */
|
||||
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);
|
||||
value = Char(wname);
|
||||
}
|
||||
|
|
@ -1123,28 +1114,29 @@ public:
|
|||
return Language::classDeclaration(n);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* classHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* Helper function that adds record to appropriate
|
||||
/* ------------------------------------------------------------
|
||||
* Helper function that adds record to appropriate
|
||||
* C arrays
|
||||
*/
|
||||
* ------------------------------------------------------------ */
|
||||
void registerClass(String *scope, Node *n) {
|
||||
String *wrap_class = Getattr(n,"wrap:class_name");
|
||||
assert(wrap_class != 0);
|
||||
assert(wrap_class);
|
||||
Hash *nspaceHash = getNamespaceHash(scope);
|
||||
String *ns_classes = Getattr(nspaceHash, "classes");
|
||||
Printv(ns_classes, "&", wrap_class, ",\n", NIL);
|
||||
if (elua_ltr || eluac_ltr) {
|
||||
String *ns_methods = Getattr(nspaceHash, "methods");
|
||||
Hash *class_hash = getNamespaceHash(class_fq_symname);
|
||||
assert(class_hash != 0);
|
||||
assert(class_hash);
|
||||
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);
|
||||
}
|
||||
}
|
||||
/* ------------------------------------------------------------
|
||||
* classHandler()
|
||||
* ------------------------------------------------------------ */
|
||||
virtual int classHandler(Node *n) {
|
||||
//REPORT("classHandler", n);
|
||||
|
||||
|
|
@ -1174,7 +1166,7 @@ public:
|
|||
else
|
||||
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);
|
||||
|
||||
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
|
||||
// any member or subclass with name "__Static". Thus, never any name clash.
|
||||
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_methods_tab_name = Getattr(instance_cls, "methods:name");
|
||||
Setattr(instance_cls, "lua:no_namespaces", "1");
|
||||
|
|
@ -1225,7 +1217,7 @@ public:
|
|||
|
||||
class_static_nspace = NewStringf("%s%s__Static", class_fq_symname, NSPACE_SEPARATOR);
|
||||
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:class_static", "1");
|
||||
|
||||
|
|
@ -1296,18 +1288,18 @@ public:
|
|||
constructor_name = constructor_proxy_name;
|
||||
if (elua_ltr) {
|
||||
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);
|
||||
} else if (eluac_ltr) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (have_destructor) {
|
||||
if (eluac_ltr) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
Basically is is a lot of search & replacing of odd sequences
|
||||
*/
|
||||
/* -----------------------------------------------------------------------------
|
||||
* EscapeCode()
|
||||
* 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) {
|
||||
//Printf(f_runtime,"/* original luacode:[[[\n%s\n]]]\n*/\n",str);
|
||||
Chop(str); // trim
|
||||
|
|
@ -1612,18 +1606,22 @@ public:
|
|||
//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
|
||||
inside namespaces_hash.
|
||||
nspace could be NULL (NSPACE_TODO), that means functions and variables and classes
|
||||
that are not in any namespace (this is default for SWIG unless %nspace feature is used)
|
||||
You can later set some attributes that will affect behaviour of functions that use this hash:
|
||||
"lua:no_namespaces" will disable "namespaces" array.
|
||||
"lua:no_classes" will disable "classes" 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;
|
||||
*/
|
||||
/* -----------------------------------------------------------------------------
|
||||
* getNamespaceHash()
|
||||
* Each namespace can be described with hash that stores C arrays
|
||||
* where members of the namespace should be added. All these hashes are stored
|
||||
* inside namespaces_hash.
|
||||
* nspace could be NULL (NSPACE_TODO), that means functions and variables and classes
|
||||
* that are not in any namespace (this is default for SWIG unless %nspace feature is used)
|
||||
* You can later set some attributes that will affect behaviour of functions that use this hash:
|
||||
* "lua:no_namespaces" will disable "namespaces" array.
|
||||
* "lua:no_classes" will disable "classes" 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 *nspace_hash = Getattr(namespaces_hash, nspace ? nspace : "");
|
||||
if (nspace_hash != 0)
|
||||
|
|
@ -1770,17 +1768,19 @@ public:
|
|||
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
|
||||
* close same hash will result in error
|
||||
* closeNamespaceHash DOES NOT print structure that describes namespace, it only
|
||||
* 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_classes" is set, then array for "classes" won't be printed
|
||||
* */
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void closeNamespaceHash(String *nspace, File *output) {
|
||||
Hash *nspace_hash = Getattr(namespaces_hash, nspace);
|
||||
assert(nspace_hash != 0);
|
||||
assert(nspace_hash);
|
||||
assert(Getattr(nspace_hash, "lua:closed") == 0);
|
||||
|
||||
Setattr(nspace_hash, "lua:closed", "1");
|
||||
|
|
@ -1836,26 +1836,26 @@ public:
|
|||
Printv(output, set_tab, NIL);
|
||||
|
||||
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(\"__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(\".set\"), LROVAL(", set_tab_name, ")},\n", NIL);
|
||||
if (Getattr(nspace_hash, "lua:class_instance")) {
|
||||
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)
|
||||
// Instead structure describing its methods isused
|
||||
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);
|
||||
// Put forward declaration of this array
|
||||
Printv(output, "extern ", Getattr(static_cls, "methods:decl"), "\n", NIL);
|
||||
} else if (Getattr(nspace_hash, "lua:class_static")) {
|
||||
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");
|
||||
assert(instance_cls_metatable_name != 0);
|
||||
assert(instance_cls_metatable_name);
|
||||
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) {
|
||||
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) {
|
||||
// Special handling for empty module.
|
||||
if (Getattr(namespaces_hash, "") == 0) {
|
||||
|
|
@ -1894,22 +1898,26 @@ public:
|
|||
name = module;
|
||||
else
|
||||
name = Getattr(nspace, "name");
|
||||
assert(name != 0);
|
||||
assert(name);
|
||||
printNamespaceDefinition(key, name, dataOutput);
|
||||
}
|
||||
Delete(to_close);
|
||||
}
|
||||
|
||||
// This function prints to output a definition of namespace in
|
||||
// form of swig_lua_namespace: { 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.
|
||||
/* -----------------------------------------------------------------------------
|
||||
* printNamespaceDefinition()
|
||||
* This function prints to output a definition of namespace in
|
||||
* form
|
||||
* 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) {
|
||||
Hash *nspace_hash = getNamespaceHash(nspace, false);
|
||||
|
||||
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);
|
||||
|
||||
String *null_string = NewString("0");
|
||||
|
|
@ -1931,12 +1939,15 @@ public:
|
|||
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
|
||||
// and depending on where are we - static class member/function,
|
||||
// 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'
|
||||
/* -----------------------------------------------------------------------------
|
||||
* luaCurrentSymbolNSpace()
|
||||
* This function determines actual namespace/scope where any symbol at the
|
||||
* current moment should be placed. It looks at the 'current' array
|
||||
* and depending on where are we - static class member/function,
|
||||
* 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 *scope = 0;
|
||||
// If ouside class, than NSpace is used.
|
||||
|
|
@ -1954,12 +1965,15 @@ public:
|
|||
} else { // Friend functions are handled this way
|
||||
scope = class_static_nspace;
|
||||
}
|
||||
assert(scope != 0);
|
||||
assert(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) {
|
||||
String *scope = luaCurrentSymbolNSpace();
|
||||
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
||||
|
|
@ -1969,7 +1983,10 @@ public:
|
|||
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) {
|
||||
//Printf(stdout, "luaAddSymbol: %s scope: %s\n", s, scope);
|
||||
int result = Language::addSymbol(s, n, scope);
|
||||
|
|
@ -1978,15 +1995,14 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
// Function creates fully qualified name of given symbol. Current NSpace and current class
|
||||
// are used
|
||||
String *fully_qualified_name(const_String_or_char_ptr name) {
|
||||
assert(name != 0);
|
||||
String *scope = 0;
|
||||
if (getCurrentClass())
|
||||
scope = class_fq_symname;
|
||||
else
|
||||
scope = getNSpace();
|
||||
/* -----------------------------------------------------------------------------
|
||||
* fullyQualifiedName()
|
||||
* Function creates fully qualified name of given symbol. The scope is deremined
|
||||
* automatically based on luaCurrentSymbolNSpace()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
String *fullyQualifiedName(const_String_or_char_ptr name) {
|
||||
assert(name);
|
||||
String *scope = luaCurrentSymbolNSpace();
|
||||
|
||||
String *fqname = 0;
|
||||
if (scope)
|
||||
|
|
@ -1997,10 +2013,13 @@ public:
|
|||
return fqname;
|
||||
}
|
||||
|
||||
// Input: symname
|
||||
// Output - wrapper around fully qualified form of symname
|
||||
String *symname_wrapper(String *symname) {
|
||||
String *fqname = fully_qualified_name(symname);
|
||||
/* -----------------------------------------------------------------------------
|
||||
* symnameWrapper()
|
||||
* Input: 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);
|
||||
Delete(fqname);
|
||||
return wname;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue