Initial implementation - everything compiles but might not work
This commit is contained in:
parent
9146164748
commit
1c5a0f8b9c
6 changed files with 655 additions and 177 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
%module nspace
|
%module nspace
|
||||||
|
|
||||||
// nspace feature only supported by these languages
|
// nspace feature only supported by these languages
|
||||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
|
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA)
|
||||||
|
|
||||||
#if defined(SWIGJAVA)
|
#if defined(SWIGJAVA)
|
||||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||||
|
|
|
||||||
|
|
@ -129,10 +129,13 @@ typedef struct {
|
||||||
swig_type_info **ptype;
|
swig_type_info **ptype;
|
||||||
} swig_lua_const_info;
|
} swig_lua_const_info;
|
||||||
|
|
||||||
|
/* TODO:REMOVE
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
lua_CFunction method;
|
lua_CFunction method;
|
||||||
} swig_lua_method;
|
} swig_lua_method;
|
||||||
|
*/
|
||||||
|
typedef luaL_Reg swig_lua_method;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
@ -140,16 +143,20 @@ typedef struct {
|
||||||
lua_CFunction setmethod;
|
lua_CFunction setmethod;
|
||||||
} swig_lua_attribute;
|
} swig_lua_attribute;
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
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;
|
||||||
} swig_lua_namespace;
|
swig_lua_class **ns_classes;
|
||||||
|
swig_lua_namespace **ns_namespaces;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct swig_lua_class {
|
struct swig_lua_class {
|
||||||
const char *name;
|
const char *name;
|
||||||
swig_type_info **type;
|
swig_type_info **type;
|
||||||
lua_CFunction constructor;
|
lua_CFunction constructor;
|
||||||
|
|
@ -159,7 +166,7 @@ typedef struct swig_lua_class {
|
||||||
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;
|
};
|
||||||
|
|
||||||
/* this is the struct for wrapping all pointers in SwigLua
|
/* this is the struct for wrapping all pointers in SwigLua
|
||||||
*/
|
*/
|
||||||
|
|
@ -497,28 +504,29 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L)
|
||||||
}
|
}
|
||||||
|
|
||||||
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_class_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);
|
||||||
|
|
||||||
/* helper function - register namespace methods and attributes into namespace */
|
/* helper function - register namespace methods and attributes into namespace */
|
||||||
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns)
|
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
assert(lua_istable(L,-1));
|
|
||||||
/* There must be table at the top of the stack */
|
/* There must be table at the top of the stack */
|
||||||
|
assert(lua_istable(L,-1));
|
||||||
SWIG_Lua_InstallConstants(L, ns->ns_constants);
|
SWIG_Lua_InstallConstants(L, ns->ns_constants);
|
||||||
|
|
||||||
lua_getmetatable(L,-1);
|
lua_getmetatable(L,-1);
|
||||||
|
|
||||||
/* add fns */
|
/* add fns */
|
||||||
for(i=0;ns->ns_attributes[i].name;i++){
|
for(i=0;ns->ns_attributes[i].name;i++){
|
||||||
SWIG_Lua_add_class_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod);
|
SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add methods to the metatable */
|
/* add methods to the metatable */
|
||||||
SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
|
SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
for(i=0;ns->ns_methods[i].name;i++){
|
for(i=0;ns->ns_methods[i].name;i++){
|
||||||
SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method);
|
SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func);
|
||||||
}
|
}
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
|
|
||||||
|
|
@ -527,12 +535,29 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace*
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* helper function. creates namespace table and add it to module table */
|
/* Register all classes in the namespace
|
||||||
SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
|
*/
|
||||||
|
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State* L, swig_lua_namespace* ns)
|
||||||
{
|
{
|
||||||
assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */
|
swig_lua_class** classes = ns->ns_classes;
|
||||||
|
|
||||||
|
if( classes != 0 ) {
|
||||||
|
while((*classes)->name != 0) {
|
||||||
|
SWIG_Lua_class_register(L, *classes);
|
||||||
|
classes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* helper function. creates namespace table and add it to module table
|
||||||
|
if 'reg' is true, then will register namespace table to parent one (must be on top of the stack
|
||||||
|
when function is called)
|
||||||
|
Function always returns newly registered table on top of the stack
|
||||||
|
*/
|
||||||
|
SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns, bool reg)
|
||||||
|
{
|
||||||
|
assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
|
||||||
lua_checkstack(L,5);
|
lua_checkstack(L,5);
|
||||||
lua_pushstring(L, ns->name);
|
|
||||||
lua_newtable(L); /* namespace itself */
|
lua_newtable(L); /* namespace itself */
|
||||||
lua_newtable(L); /* metatable for namespace */
|
lua_newtable(L); /* metatable for namespace */
|
||||||
|
|
||||||
|
|
@ -554,8 +579,23 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
|
||||||
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set);
|
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set);
|
||||||
|
|
||||||
lua_setmetatable(L,-2); /* set metatable */
|
lua_setmetatable(L,-2); /* set metatable */
|
||||||
lua_rawset(L,-3); /* add namespace to module table */
|
|
||||||
return 0;
|
// Register all functions, variables etc
|
||||||
|
SWIG_Lua_add_namespace_details(L,ns);
|
||||||
|
|
||||||
|
swig_lua_namespace** sub_namespace = ns->ns_namespaces;
|
||||||
|
if( sub_namespace != 0) {
|
||||||
|
while((*sub_namespace)->name != 0) {
|
||||||
|
SWIG_Lua_namespace_register(L, *sub_namespace, true);
|
||||||
|
sub_namespace++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reg) {
|
||||||
|
lua_pushstring(L,ns->name);
|
||||||
|
lua_pushvalue(L,-2);
|
||||||
|
lua_rawset(L,-4); /* add namespace to module table */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* global variable support code: classes
|
* global variable support code: classes
|
||||||
|
|
@ -757,7 +797,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* helper add a variable to a registered class */
|
/* helper add a variable to a registered class */
|
||||||
SWIGINTERN void SWIG_Lua_add_class_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)
|
||||||
{
|
{
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
SWIG_Lua_get_table(L,".get"); /* find the .get table */
|
SWIG_Lua_get_table(L,".get"); /* find the .get table */
|
||||||
|
|
@ -799,13 +839,13 @@ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss)
|
||||||
}
|
}
|
||||||
/* add fns */
|
/* add fns */
|
||||||
for(i=0;clss->attributes[i].name;i++){
|
for(i=0;clss->attributes[i].name;i++){
|
||||||
SWIG_Lua_add_class_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);
|
||||||
}
|
}
|
||||||
/* add methods to the metatable */
|
/* add methods to the metatable */
|
||||||
SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
|
SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
for(i=0;clss->methods[i].name;i++){
|
for(i=0;clss->methods[i].name;i++){
|
||||||
SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
|
SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func);
|
||||||
}
|
}
|
||||||
lua_pop(L,1); /* tidy stack (remove table) */
|
lua_pop(L,1); /* tidy stack (remove table) */
|
||||||
/* add operator overloads
|
/* add operator overloads
|
||||||
|
|
@ -814,7 +854,7 @@ SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss)
|
||||||
(this might mess up is someone defines a method __gc (the destructor)*/
|
(this might mess up is someone defines a method __gc (the destructor)*/
|
||||||
for(i=0;clss->methods[i].name;i++){
|
for(i=0;clss->methods[i].name;i++){
|
||||||
if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){
|
if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){
|
||||||
SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
|
SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -848,7 +888,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */
|
assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */
|
||||||
|
|
||||||
SWIG_Lua_namespace_register(L,&clss->cls_static);
|
SWIG_Lua_namespace_register(L,&clss->cls_static, false);
|
||||||
|
|
||||||
SWIG_Lua_get_table(L,clss->name); // Get namespace table back
|
SWIG_Lua_get_table(L,clss->name); // Get namespace table back
|
||||||
assert(lua_istable(L,-1)); /* just in case */
|
assert(lua_istable(L,-1)); /* just in case */
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,6 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
|
||||||
/* add a global fn */
|
/* add a global fn */
|
||||||
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
|
SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
|
||||||
SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
|
SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
|
||||||
/* begin the module (its a table with the same name as the module) */
|
|
||||||
SWIG_Lua_module_begin(L,SWIG_name);
|
|
||||||
/* add commands/functions */
|
|
||||||
for (i = 0; swig_commands[i].name; i++){
|
|
||||||
SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].func);
|
|
||||||
}
|
|
||||||
/* add variables */
|
|
||||||
for (i = 0; swig_variables[i].name; i++){
|
|
||||||
SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
|
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
|
||||||
|
|
@ -59,17 +49,16 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
|
||||||
SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
|
SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* additional registration structs & classes in lua */
|
bool globalRegister = false;
|
||||||
for (i = 0; swig_types[i]; i++){
|
#ifdef SWIG_LUA_MODULE_GLOBAL
|
||||||
if (swig_types[i]->clientdata){
|
globalRegister = true;
|
||||||
SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
|
#endif
|
||||||
}
|
SWIG_Lua_namespace_register(L,&swig___Global, globalRegister);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#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))
|
||||||
/* constants */
|
/* constants */
|
||||||
SWIG_Lua_InstallConstants(L,swig_constants);
|
/* TODO: REMOVE */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
|
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
|
||||||
|
|
|
||||||
|
|
@ -3049,6 +3049,7 @@ void Language::main(int argc, char *argv[]) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
|
int Language::addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope) {
|
||||||
|
//Printf( stdout, "addSymbol: %s %s\n", s, scope );
|
||||||
Hash *symbols = Getattr(symtabs, scope ? scope : "");
|
Hash *symbols = Getattr(symtabs, scope ? scope : "");
|
||||||
if (!symbols) {
|
if (!symbols) {
|
||||||
// New scope which has not been added by the target language - lazily created.
|
// New scope which has not been added by the target language - lazily created.
|
||||||
|
|
@ -3468,6 +3469,13 @@ String *Language::getNSpace() const {
|
||||||
return NSpace;
|
return NSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Language::setNSpace()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
void Language::setNSpace(String *nspace) {
|
||||||
|
NSpace = nspace;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Language::getClassName()
|
* Language::getClassName()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -278,6 +278,7 @@ protected:
|
||||||
|
|
||||||
/* Return the namespace for the class/enum - the nspace feature */
|
/* Return the namespace for the class/enum - the nspace feature */
|
||||||
String *getNSpace() const;
|
String *getNSpace() const;
|
||||||
|
void setNSpace(String *nspace);
|
||||||
|
|
||||||
/* Return the real name of the current class */
|
/* Return the real name of the current class */
|
||||||
String *getClassName() const;
|
String *getClassName() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue