Merge branch 'class_p1_fixes' of github.com:v-for-vandal/swig into v-for-vandal-class_p1_fixes
Lua changes tweaks. * 'class_p1_fixes' of github.com:v-for-vandal/swig: Removing all TODO:REMOVE Fixing enums __Static -> SwigStatig, __Module -> SwigModule Setattr -> SetFlag Backward compatibility -> Compatibility Note Fixing documentation. Adding an example.
This commit is contained in:
commit
8b75b90b2f
10 changed files with 180 additions and 158 deletions
|
|
@ -510,14 +510,16 @@ Enums are exported into a class table. For example, given some enums:
|
|||
enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
|
||||
struct Test {
|
||||
enum { TEST1 = 10, TEST2 = 20 };
|
||||
#ifdef __cplusplus // There are no static members in C language
|
||||
static const int ICONST = 12;
|
||||
#endif
|
||||
};
|
||||
</pre></div>
|
||||
<p>
|
||||
This is 'effectively' converted into the following Lua code:
|
||||
There is a slight difference in behaviour in C mode and C++ model. In C++ mode this is 'effectively' converted into the following Lua code:
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.const.SUNDAY)
|
||||
> print(example.SUNDAY)
|
||||
0
|
||||
> print(example.Test.TEST1)
|
||||
10
|
||||
|
|
@ -525,6 +527,15 @@ This is 'effectively' converted into the following Lua code:
|
|||
12
|
||||
</pre></div>
|
||||
|
||||
<p>In C mode enums from structs are exported into global namespace (due to C Standard). See below:</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.SUNDAY)
|
||||
0
|
||||
> -- See the difference here
|
||||
> print(example.TEST1)
|
||||
10
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note:</b> Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above.
|
||||
The following code was the only way to access these constants/enums:
|
||||
|
|
@ -540,17 +551,17 @@ The old-style bindings are still generated in addition to the new ones.
|
|||
If the <tt>-no-old-metatable-bindings</tt> option is used, then these old-style bindings are not generated.
|
||||
</p>
|
||||
<p>
|
||||
However, in C mode, names of enums are not prefixed with names of structure. This is the due to the C Standard.
|
||||
However, in C mode, prefixed names of enums are not exported. There is no sense in having both Test_TEST1 and TEST1 in global namespace.
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.TEST1)
|
||||
10
|
||||
> print(example.ICONST)
|
||||
12
|
||||
> print(example.Test_TEST1)
|
||||
nil
|
||||
</pre></div>
|
||||
<p>
|
||||
It is worth mentioning, that <tt>example.Test.TEST1</tt> and <tt>example.Test_TEST1</tt> are different entities and changing one does not change the other.
|
||||
Given the fact, that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.
|
||||
Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.
|
||||
</p>
|
||||
<H3><a name="Lua_nn12"></a>26.3.5 Pointers</H3>
|
||||
|
||||
|
|
@ -1346,15 +1357,20 @@ int module_variable = 9;
|
|||
namespace MyWorld {
|
||||
class World {
|
||||
public:
|
||||
World():
|
||||
world_max_count(9) {}
|
||||
int create_world() { return 17; }
|
||||
const int world_max_count = 9;
|
||||
const int world_max_count; // = 9
|
||||
};
|
||||
namespace Nested {
|
||||
class Dweller {
|
||||
enum Gender { MALE, FEMALE };
|
||||
static int populate_cave() { return 19; }
|
||||
int create_cave() { return 13; }
|
||||
int food_count; // = 11
|
||||
public:
|
||||
Dweller():
|
||||
food_count(11) {}
|
||||
enum Gender { MALE = 0, FEMALE = 1 };
|
||||
static int populate_cave() { return 19; }
|
||||
int create_cave() { return 13; }
|
||||
int food_count; // = 11
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1364,18 +1380,16 @@ Now, from Lua usage is as follows:
|
|||
> print(example.module_function())
|
||||
7
|
||||
> print(example.module_variable)
|
||||
8
|
||||
9
|
||||
> print(example.MyWorld.World():create_world())
|
||||
17
|
||||
> print(example.MyWorld.World.world_max_count)
|
||||
9
|
||||
> print(example.MyWorld.Nested.Dweller.MALE)
|
||||
0
|
||||
> print(example.MyWorld.Nested.Dweller().food_count)
|
||||
11
|
||||
>
|
||||
</pre></div>
|
||||
<H4> Backward compatibility </H4>
|
||||
<H4> Compatibility Note </H4>
|
||||
<p>
|
||||
If SWIG is running in backward compatible way, i.e. without <tt>-no-old-metatable-bindings</tt> option, then additional old-style names are generated(notice the underscore):
|
||||
</p>
|
||||
|
|
@ -1387,7 +1401,7 @@ If SWIG is running in backward compatible way, i.e. without <tt>-no-old-metatabl
|
|||
11
|
||||
>
|
||||
</pre></div>
|
||||
<H3> Backward compatibility </H3>
|
||||
<H3> Compatibility Note </H3>
|
||||
<H4> Names </H4>
|
||||
<p> If SWIG is launched without <tt>-no-old-metatable-bindings</tt> option, then it enters backward-compatible mode. While in this mode, it tries
|
||||
to generate additional names for static functions, class static constants and class enums.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ funcptr3
|
|||
functest
|
||||
functor
|
||||
import
|
||||
nspace
|
||||
owner
|
||||
pointer
|
||||
simple
|
||||
|
|
|
|||
19
Examples/lua/nspace/Makefile
Normal file
19
Examples/lua/nspace/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile lua_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile lua_clean
|
||||
28
Examples/lua/nspace/example.h
Normal file
28
Examples/lua/nspace/example.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef _example_guardian_
|
||||
#define _example_guardian_
|
||||
|
||||
int module_function() { return 7; }
|
||||
int module_variable = 9;
|
||||
|
||||
namespace MyWorld {
|
||||
class World {
|
||||
public:
|
||||
World():
|
||||
world_max_count(9) {}
|
||||
int create_world() { return 17; }
|
||||
const int world_max_count; // = 9
|
||||
};
|
||||
namespace Nested {
|
||||
class Dweller {
|
||||
public:
|
||||
Dweller():
|
||||
food_count(11) {}
|
||||
enum Gender { MALE = 0, FEMALE = 1 };
|
||||
static int populate_cave() { return 19; }
|
||||
int create_cave() { return 13; }
|
||||
int food_count; // = 11
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
10
Examples/lua/nspace/example.i
Normal file
10
Examples/lua/nspace/example.i
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%nspace MyWorld::Nested::Dweller;
|
||||
%nspace MyWorld::World;
|
||||
|
||||
%include "example.h"
|
||||
41
Examples/lua/nspace/runme.lua
Normal file
41
Examples/lua/nspace/runme.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- file: runme.lua
|
||||
|
||||
-- This file illustrates class C++ interface generated
|
||||
-- by SWIG.
|
||||
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require('example')
|
||||
end
|
||||
|
||||
ex = example
|
||||
|
||||
-- Calling a module function ( aka global function )
|
||||
assert( ex.module_function() == 7 )
|
||||
print("example.module_function(): ", ex.module_function())
|
||||
|
||||
-- Accessing a module (aka global) variable
|
||||
assert( ex.module_variable == 9 )
|
||||
print("example.module_variable: ", ex.module_variable)
|
||||
|
||||
-- Creating an instance of the class
|
||||
w1 = ex.MyWorld.World()
|
||||
print("Creating class instance: w1 = ex.MyWorld.World(): ", w1)
|
||||
|
||||
-- Accessing class members
|
||||
assert( ex.MyWorld.World():create_world() == 17 )
|
||||
print( "w1:create_world() = ", w1:create_world() )
|
||||
assert( w1:create_world() == 17 )
|
||||
print( "w1:world_max_count = ", w1.world_max_count )
|
||||
assert( w1.world_max_count == 9 )
|
||||
|
||||
-- Accessing enums from class within namespace
|
||||
print( "Accessing enums: ex.MyWorld.Nested.Dweller.MALE = ", ex.MyWorld.Nested.Dweller.MALE )
|
||||
assert( ex.MyWorld.Nested.Dweller.MALE == 0 )
|
||||
assert( ex.MyWorld.Nested.Dweller.FEMALE == 1 )
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ assert(enums.globalinstance3==30)
|
|||
assert(enums.AnonEnum1==0)
|
||||
assert(enums.AnonEnum2==100)
|
||||
|
||||
-- In C enums from struct are exported without prefixing with struct name
|
||||
-- In C++ they are prefixed.
|
||||
-- In C enums from struct are exported into global namespace (without prefixing with struct name)
|
||||
-- In C++ they are prefixed (as compatibility thing).
|
||||
-- We are emulating xor :)
|
||||
assert(enums.BAR1 ~= enums.Foo_BAR1) -- It is either C style, or C++ style, but not both
|
||||
assert((enums.BAR1 ~= nil ) or (enums.Foo_BAR1 ~= nil))
|
||||
|
|
|
|||
|
|
@ -379,8 +379,6 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L)
|
|||
}
|
||||
|
||||
#ifdef SWIG_LUA_ELUA_EMULATE
|
||||
//#define report(...) printf(__VA_ARGS__) // TODO: REMOVE
|
||||
#define report(...) // TODO : REMOVE
|
||||
|
||||
SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own);
|
||||
SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type);
|
||||
|
|
@ -405,30 +403,20 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
|
|||
int i;
|
||||
int table_parsed = 0;
|
||||
int pairs_start = lua_gettop(L);
|
||||
static int tabs_count = 0; // TODO: REMOVE
|
||||
for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
|
||||
{
|
||||
/* TODO: REMOVE */
|
||||
int j = 0;
|
||||
for(j=0;j<tabs_count;j++) report(" ");
|
||||
/* END OF REMOVE */
|
||||
|
||||
report("Registering %d", int(i)); // TODO: REMOVE
|
||||
const swig_elua_entry *entry = table + i;
|
||||
int is_metatable = 0;
|
||||
switch(entry->key.type) {
|
||||
case LUA_TSTRING:
|
||||
lua_pushstring(L,entry->key.key.strkey);
|
||||
report(" %s :", entry->key.key.strkey); // TODO: REMOVE
|
||||
if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0)
|
||||
is_metatable = 1;
|
||||
break;
|
||||
case LUA_TNUMBER:
|
||||
lua_pushnumber(L,entry->key.key.numkey);
|
||||
report(" %f :", (double)(entry->key.key.numkey)); // TODO: REMOVE
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
report(" nil :"); // TODO: REMOVE
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -437,39 +425,27 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
|
|||
switch(entry->value.type) {
|
||||
case LUA_TSTRING:
|
||||
lua_pushstring(L,entry->value.value.string);
|
||||
report(" %s", entry->value.value.string); // TODO: REMOVE
|
||||
break;
|
||||
case LUA_TNUMBER:
|
||||
lua_pushnumber(L,entry->value.value.number);
|
||||
report(" %f", (double)(entry->value.value.number)); // TODO: REMOVE
|
||||
break;
|
||||
case LUA_TFUNCTION:
|
||||
report(" %p", (void*)(entry->value.value.function)); // TODO: REMOVE
|
||||
lua_pushcfunction(L,entry->value.value.function);
|
||||
break;
|
||||
case LUA_TTABLE:
|
||||
/* TODO: REMOVE */
|
||||
report(" table");
|
||||
tabs_count++;
|
||||
/* END OF REMOVE */
|
||||
lua_rawgetp(L,parsed_tables_array, entry->value.value.table);
|
||||
table_parsed = !lua_isnil(L,-1);
|
||||
if(!table_parsed) {
|
||||
lua_pop(L,1); /*remove nil */
|
||||
report("\n"); // TODO: REMOVE
|
||||
lua_newtable(L);
|
||||
SWIG_Lua_elua_emulate_register(L,entry->value.value.table);
|
||||
} else {
|
||||
report(" already parsed"); // TODO: REMOVE
|
||||
}
|
||||
}
|
||||
if(is_metatable) {
|
||||
report(" (registering metatable)"); // TODO: REMOVE
|
||||
assert(lua_istable(L,-1));
|
||||
lua_pushvalue(L,-1);
|
||||
lua_setmetatable(L,target_table);
|
||||
}
|
||||
|
||||
tabs_count--; /*TODO: REMOVE*/
|
||||
break;
|
||||
case LUA_TUSERDATA:
|
||||
if(entry->value.value.userdata.member)
|
||||
|
|
@ -481,7 +457,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
|
|||
*(entry->value.value.userdata.ptype),0);
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
report(" nil"); // TODO: REMOVE
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -489,7 +464,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
|
|||
}
|
||||
assert(lua_gettop(L) == pairs_start + 2);
|
||||
lua_rawset(L,target_table);
|
||||
report("\n"); // TODO: REMOVE
|
||||
}
|
||||
lua_pop(L,1); /* Removing parsed tables storage */
|
||||
assert(lua_gettop(L) == target_table);
|
||||
|
|
@ -501,7 +475,6 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L)
|
|||
lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
|
||||
}
|
||||
|
||||
/* TODO: REMOVE */
|
||||
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L);
|
||||
|
||||
SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
|
||||
|
|
@ -519,7 +492,6 @@ SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
|
|||
/*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/
|
||||
assert(lua_gettop(L) == 2);
|
||||
if(lua_istable(L,-2)) {
|
||||
printf("getmetatable: elua emulation part\n"); // TODO: REMOVE
|
||||
lua_pop(L,1); /*remove the nil*/
|
||||
lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY);
|
||||
}
|
||||
|
|
@ -533,7 +505,6 @@ fail:
|
|||
|
||||
SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
|
||||
{
|
||||
int begin = lua_gettop(L); // TODO: REMOVE
|
||||
SWIG_Lua_get_class_registry(L);
|
||||
lua_pushglobaltable(L);
|
||||
lua_pushstring(L,"lua_getmetatable");
|
||||
|
|
@ -544,7 +515,6 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
|
|||
lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
|
||||
lua_rawset(L,-3);
|
||||
lua_pop(L,2);
|
||||
assert(lua_gettop(L) == begin); // TODO: REMOVE
|
||||
|
||||
}
|
||||
/* END OF REMOVE */
|
||||
|
|
@ -619,7 +589,6 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
|
|||
}
|
||||
lua_pop(L,1); /* remove the value .set table */
|
||||
lua_pop(L,1); /* remote metatable */
|
||||
assert(lua_gettop(L) == 3); // TODO: REMOVE
|
||||
lua_rawset(L,-3);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -805,7 +774,6 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i
|
|||
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 */
|
||||
if(ret) assert(lua_gettop(L) == subcall_last_arg + *ret); // TODO: REMOVE
|
||||
if(result != SWIG_ERROR) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -817,7 +785,6 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i
|
|||
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 */
|
||||
lua_pop(L, lua_gettop(L) - last_arg);
|
||||
|
|
@ -842,11 +809,6 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int fi
|
|||
assert(lua_isuserdata(L,-2)); /* just in case */
|
||||
lua_getmetatable(L,-2); /* get the meta table */
|
||||
assert(lua_istable(L,-1)); /* just in case */
|
||||
// TODO: REMOVE
|
||||
//SWIG_Lua_get_table(L,".type");
|
||||
//printf("class %s get %s\n", lua_tostring(L,-1), lua_tostring(L,substack_start+2));
|
||||
//lua_pop(L,1);
|
||||
// END OF REMOVE
|
||||
SWIG_Lua_get_table(L,".get"); /* find the .get table */
|
||||
assert(lua_istable(L,-1)); /* just in case */
|
||||
/* look for the key in the .get table */
|
||||
|
|
@ -893,24 +855,8 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int fi
|
|||
/* Remove the metatable */
|
||||
lua_pop(L,1);
|
||||
/* Search in base classes */
|
||||
assert(lua_gettop(L) == substack_start + 2); // TODO: REMOVE
|
||||
|
||||
/* TODO: REMOVE
|
||||
#ifdef SWIG_LUA_SQUASH_BASES
|
||||
if(ret) *ret = 0;
|
||||
return SWIG_ERROR; // TODO:ERROR:FIX:REMOVE!!!!
|
||||
//#warning REMOVE REMOVE REMOVE
|
||||
#endif
|
||||
END OF 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);
|
||||
if(ret) assert(lua_gettop(L) == substack_start + 2 + *ret); // TODO: REMOVE
|
||||
// TODO: REMOVE
|
||||
if(bases_search_result != SWIG_OK) {
|
||||
//printf("failed.\n");
|
||||
}
|
||||
// END OF REMOVE
|
||||
return bases_search_result; /* sorry not known */
|
||||
}
|
||||
|
||||
|
|
@ -971,7 +917,6 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
|||
} else {
|
||||
lua_pop(L,1); /* remove the answer for .set table request*/
|
||||
}
|
||||
assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE
|
||||
/* NEW: looks for the __setitem() fn
|
||||
this is a user provided set fn */
|
||||
SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
|
||||
|
|
@ -985,11 +930,9 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
|
|||
return SWIG_OK;
|
||||
}
|
||||
lua_pop(L,1); /* remove value */
|
||||
assert(lua_gettop(L) == substack_start + 4); // TODO: REMOVE
|
||||
|
||||
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);
|
||||
|
|
@ -1144,7 +1087,6 @@ SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int sour
|
|||
/* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
|
||||
SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
|
||||
{
|
||||
int begin = lua_gettop(L); // TODO:REMOVE
|
||||
/* push original[name], then base[name] */
|
||||
lua_pushstring(L,name);
|
||||
lua_rawget(L,original);
|
||||
|
|
@ -1155,13 +1097,11 @@ SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int origina
|
|||
SWIG_Lua_merge_tables_by_index(L, original_table, base_table);
|
||||
/* clearing stack */
|
||||
lua_pop(L,2);
|
||||
assert(lua_gettop(L) == begin); // TODO: REMOVE
|
||||
}
|
||||
|
||||
/* Function takes all symbols from base and adds it to derived class. It's just a helper. */
|
||||
SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
|
||||
{
|
||||
int begin = lua_gettop(L); // TODO:REMOVE
|
||||
/* There is one parameter - original, i.e. 'derived' class metatable */
|
||||
assert(lua_istable(L,-1));
|
||||
int original = lua_gettop(L);
|
||||
|
|
@ -1171,13 +1111,11 @@ SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls
|
|||
SWIG_Lua_merge_tables(L, ".set", original, base );
|
||||
SWIG_Lua_merge_tables(L, ".get", original, base );
|
||||
lua_pop(L,1);
|
||||
assert(lua_gettop(L) == begin); // TODO: REMOVE
|
||||
}
|
||||
|
||||
/* Function squashes all symbols from 'clss' bases into itself */
|
||||
SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
|
||||
{
|
||||
int begin = lua_gettop(L); // TODO: REMOVE
|
||||
int i;
|
||||
SWIG_Lua_get_class_metatable(L,clss->fqname);
|
||||
for(i=0;clss->base_names[i];i++)
|
||||
|
|
@ -1191,7 +1129,6 @@ SWIGINTERN int SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
|
|||
SWIG_Lua_class_squash_base(L, clss->bases[i]);
|
||||
}
|
||||
lua_pop(L,1); /*tidy stack*/
|
||||
assert(lua_gettop(L) == begin); // TODO: REMOVE
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1263,7 +1200,6 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class
|
|||
*/
|
||||
if(clss->metatable) {
|
||||
for(i=0;clss->metatable[i].name;i++) {
|
||||
assert(clss->metatable[i].func != 0); // TODO: REMOVE
|
||||
SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func);
|
||||
}
|
||||
}
|
||||
|
|
@ -1332,7 +1268,6 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
|
|||
* It would get us all special methods: __getitem, __add etc.
|
||||
* This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
|
||||
*/
|
||||
int squash_begin = lua_gettop(L); // TODO:REMOVE
|
||||
int new_metatable_index = lua_absindex(L,-1);
|
||||
for(i=0;clss->bases[i];i++)
|
||||
{
|
||||
|
|
@ -1341,7 +1276,6 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
|
|||
SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
|
||||
lua_pop(L,1);
|
||||
}
|
||||
assert(lua_gettop(L) == squash_begin); // TODO: REMOVE
|
||||
/* And now we will overwrite all incorrectly set data */
|
||||
#endif
|
||||
/* add string of class name called ".type" */
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
|
|||
|
||||
|
||||
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
|
||||
SWIG_Lua_namespace_register(L,&swig___Module, globalRegister);
|
||||
SWIG_Lua_namespace_register(L,&swig_SwigModule, globalRegister);
|
||||
#endif
|
||||
|
||||
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ private:
|
|||
// then it is basically C++ fully qualified name with colons replaced with dots.
|
||||
String *full_proxy_class_name;
|
||||
// All static methods and/or variables are treated as if they were in the
|
||||
// special C++ namespace $(classname).__Static. This is internal mechanism only
|
||||
// special C++ namespace $(classname).SwigStatic. This is internal mechanism only
|
||||
// and is not visible to user in any manner. This variable holds the name
|
||||
// of such pseudo-namespace a.k.a the result of above expression evaluation
|
||||
String *class_static_nspace;
|
||||
|
|
@ -486,8 +486,6 @@ public:
|
|||
}
|
||||
}
|
||||
wrapname = Swig_name_wrapper(mrename);
|
||||
//Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n",
|
||||
// Getattr(n, "lua:name"), symname, mrename, wrapname, luaScope ); // TODO: REMOVE
|
||||
registerMethod(n, wrapname, luaScope);
|
||||
}
|
||||
|
||||
|
|
@ -901,10 +899,6 @@ public:
|
|||
// Remember C name of the wrapping function
|
||||
Setattr(n, "wrap:name", wname);
|
||||
|
||||
/* TODO: REMOVE
|
||||
if (functionWrapperRegisterNow()) { // emit normal fns & static fns
|
||||
registerMethod(n);
|
||||
}*/
|
||||
if (current[CONSTRUCTOR]) {
|
||||
if (constructor_name != 0)
|
||||
Delete(constructor_name);
|
||||
|
|
@ -965,8 +959,6 @@ public:
|
|||
getName = Swig_name_wrapper(getName);
|
||||
if (setName)
|
||||
setName = Swig_name_wrapper(setName);
|
||||
//Printf(stdout, "luaname %s, symname %s mrename %s getName %s\n\tscope %s\n\tassignable %d\n",
|
||||
// Getattr(n, "lua:name"), symname, mrename, getName, luaScope, assignable ); // TODO: REMOVE
|
||||
registerVariable(luaScope, n, getName, setName);
|
||||
}
|
||||
|
||||
|
|
@ -1017,8 +1009,6 @@ public:
|
|||
current[VARIABLE] = true;
|
||||
// let SWIG generate the wrappers
|
||||
int result = Language::variableWrapper(n);
|
||||
// TODO: REMOVE
|
||||
//registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name");
|
||||
|
||||
// It is impossible to use registerVariable, because sym:name of the Node is currently
|
||||
// in an undefined state - the callees of this function may have modified it.
|
||||
|
|
@ -1087,7 +1077,6 @@ public:
|
|||
}
|
||||
|
||||
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
|
||||
//Printf(stdout, "tm v1: %s\n", tm); // TODO:REMOVE
|
||||
Replaceall(tm, "$source", value);
|
||||
Replaceall(tm, "$target", lua_name);
|
||||
Replaceall(tm, "$value", value);
|
||||
|
|
@ -1110,47 +1099,41 @@ public:
|
|||
bool make_v2_compatible = v2_compatibility && getCurrentClass() != 0;
|
||||
|
||||
if (make_v2_compatible) {
|
||||
// Special handling for enums in C mode - they are not prefixed with structure name
|
||||
if(!CPlusPlus && current[ENUM_CONST]) {
|
||||
lua_name_v2 = lua_name;
|
||||
DohIncref(lua_name_v2);
|
||||
iname_v2 = iname;
|
||||
DohIncref(iname_v2);
|
||||
} else {
|
||||
// Don't do anything for enums in C mode - they are already
|
||||
// wrapped correctly
|
||||
if (CPlusPlus || !current[ENUM_CONST]) {
|
||||
lua_name_v2 = Swig_name_member(0, proxy_class_name, lua_name);
|
||||
iname_v2 = Swig_name_member(0, proxy_class_name, iname);
|
||||
}
|
||||
n_v2 = Copy(n);
|
||||
//Printf( stdout, "target name v2: %s, symname v2 %s\n", lua_name_v2.ptr(), iname_v2.ptr());// TODO:REMOVE
|
||||
if (!luaAddSymbol(iname_v2, n, getNSpace())) {
|
||||
Swig_restore(n);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
n_v2 = Copy(n);
|
||||
if (!luaAddSymbol(iname_v2, n, getNSpace())) {
|
||||
Swig_restore(n);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
Setattr(n_v2, "sym:name", lua_name_v2);
|
||||
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
|
||||
if (tm_v2) {
|
||||
//Printf(stdout, "tm v2: %s\n", tm_v2.ptr()); // TODO:REMOVE
|
||||
Replaceall(tm_v2, "$source", value);
|
||||
Replaceall(tm_v2, "$target", lua_name_v2);
|
||||
Replaceall(tm_v2, "$value", value);
|
||||
Replaceall(tm_v2, "$nsname", nsname);
|
||||
registerConstant(getNSpace(), tm_v2);
|
||||
} else {
|
||||
tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0);
|
||||
if (!tm_v2) {
|
||||
// This can't be.
|
||||
assert(false);
|
||||
Swig_restore(n);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Replaceall(tm_v2, "$source", value);
|
||||
Replaceall(tm_v2, "$target", lua_name_v2);
|
||||
Replaceall(tm_v2, "$value", value);
|
||||
Replaceall(tm_v2, "$nsname", nsname);
|
||||
Printf(f_init, "%s\n", tm_v2);
|
||||
Setattr(n_v2, "sym:name", lua_name_v2);
|
||||
tm_v2 = Swig_typemap_lookup("consttab", n_v2, name, 0);
|
||||
if (tm_v2) {
|
||||
Replaceall(tm_v2, "$source", value);
|
||||
Replaceall(tm_v2, "$target", lua_name_v2);
|
||||
Replaceall(tm_v2, "$value", value);
|
||||
Replaceall(tm_v2, "$nsname", nsname);
|
||||
registerConstant(getNSpace(), tm_v2);
|
||||
} else {
|
||||
tm_v2 = Swig_typemap_lookup("constcode", n_v2, name, 0);
|
||||
if (!tm_v2) {
|
||||
// This can't be.
|
||||
assert(false);
|
||||
Swig_restore(n);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Replaceall(tm_v2, "$source", value);
|
||||
Replaceall(tm_v2, "$target", lua_name_v2);
|
||||
Replaceall(tm_v2, "$value", value);
|
||||
Replaceall(tm_v2, "$nsname", nsname);
|
||||
Printf(f_init, "%s\n", tm_v2);
|
||||
}
|
||||
Delete(n_v2);
|
||||
}
|
||||
Delete(n_v2);
|
||||
}
|
||||
|
||||
Swig_restore(n);
|
||||
|
|
@ -1301,7 +1284,7 @@ public:
|
|||
proxy_class_name = 0;
|
||||
return SWIG_NOWRAP;
|
||||
}
|
||||
Setattr(emitted, mangled_fr_t, "1");
|
||||
SetFlag(emitted, mangled_fr_t);
|
||||
|
||||
// We treat class T as both 'class' and 'namespace'. All static members, attributes
|
||||
// and constants are considered part of namespace T, all members - part of the 'class'
|
||||
|
|
@ -1309,28 +1292,25 @@ public:
|
|||
// are described with same structures - swig_lua_attribute/swig_lua_method. Instead of calling
|
||||
// getCArraysHash(class name) to initialize things for static methods/attributes and then
|
||||
// manually doing same initialization for non-static methods, we call getCArraysHash 2 times:
|
||||
// 1) With name "class name" + "." + "__Static" to initialize static things
|
||||
// 1) With name "class name" + "." + "SwigStatic" to initialize static things
|
||||
// 2) With "class name" to initialize non-static things
|
||||
// And we can guarantee that there will not be any name collision because names starting with 2 underscores
|
||||
// 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 = getCArraysHash(full_proxy_class_name, false);
|
||||
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");
|
||||
Setattr(instance_cls, "lua:no_classes", "1");
|
||||
Setattr(instance_cls, "lua:class_instance", "1");
|
||||
SetFlag(instance_cls, "lua:no_namespaces");
|
||||
SetFlag(instance_cls, "lua:no_classes");
|
||||
SetFlag(instance_cls, "lua:class_instance");
|
||||
|
||||
/* There is no use for "constants", "classes" and "namespaces" arrays.
|
||||
* All constants are considered part of static part of class.
|
||||
*/
|
||||
|
||||
class_static_nspace = NewStringf("%s%s__Static", full_proxy_class_name, NSPACE_SEPARATOR);
|
||||
class_static_nspace = NewStringf("%s%sSwigStatic", full_proxy_class_name, NSPACE_SEPARATOR);
|
||||
Hash *static_cls = getCArraysHash(class_static_nspace, false);
|
||||
assert(static_cls);
|
||||
Setattr(static_cls, "lua:no_namespaces", "1");
|
||||
Setattr(static_cls, "lua:class_static", "1");
|
||||
SetFlag(static_cls, "lua:no_namespaces");
|
||||
SetFlag(static_cls, "lua:class_static");
|
||||
|
||||
// Notifying instance_cls and static_cls hashes about each other
|
||||
Setattr(instance_cls, "lua:class_instance:static_hash", static_cls);
|
||||
|
|
@ -1479,7 +1459,6 @@ public:
|
|||
Printf(f_wrappers, ", %s, %s, &%s", s_methods_tab_name, s_attr_tab_name, Getattr(static_cls, "cname"));
|
||||
|
||||
if (!eluac_ltr) {
|
||||
assert(Getattr(instance_cls, "metatable:name")); // TODO: REMOVE
|
||||
Printf(f_wrappers, ", %s", Getattr(instance_cls,"metatable:name"));
|
||||
}
|
||||
else
|
||||
|
|
@ -1520,7 +1499,6 @@ public:
|
|||
current[MEMBER_FUNC] = true;
|
||||
Language::memberfunctionHandler(n);
|
||||
|
||||
//Printf( stdout, "add member function: %s to %s\n", symname, luaCurrentSymbolNSpace());// TODO: REMOVE
|
||||
registerMethod(n);
|
||||
current[MEMBER_FUNC] = false;
|
||||
return SWIG_OK;
|
||||
|
|
@ -1675,7 +1653,6 @@ public:
|
|||
// not the C++ name. This is because an earlier version used such a scheme for static function
|
||||
// name generation and we have to maintain backward compatibility.
|
||||
String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name);
|
||||
//Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE
|
||||
if (!GetFlag(n, "wrappedasconstant")) {
|
||||
Setattr(n, "lua:name", v2_name);
|
||||
// Registering static var in the class parent nspace
|
||||
|
|
@ -1809,7 +1786,7 @@ public:
|
|||
carrays_hash = NewHash();
|
||||
String *mangled_name = 0;
|
||||
if (nspace == 0 || Len(nspace) == 0)
|
||||
mangled_name = NewString("__Module"); // C++ names can't start with "__ + capital letter"
|
||||
mangled_name = NewString("SwigModule");
|
||||
else
|
||||
mangled_name = Swig_name_mangle(nspace);
|
||||
String *cname = NewStringf("swig_%s", mangled_name);
|
||||
|
|
@ -1907,8 +1884,6 @@ public:
|
|||
Printf(metatable_tab, "const LUA_REG_TYPE ");
|
||||
else
|
||||
Printf(metatable_tab, "static swig_lua_method ");
|
||||
assert(metatable_tab); // TODO: REMOVE
|
||||
assert(metatable_tab_name); // TODO: REMOVE
|
||||
Printv(metatable_tab, metatable_tab_name, "[]", NIL);
|
||||
Printv(metatable_tab_decl, metatable_tab, ";", NIL);
|
||||
Printv(metatable_tab, " = {\n", NIL);
|
||||
|
|
@ -1932,7 +1907,6 @@ public:
|
|||
String *item = Getitem(components, i);
|
||||
Printv(parent_path, item, NIL);
|
||||
}
|
||||
//Printf(stdout, "Registering %s. User name %s. C-name %s, Parent is %s\n", mangled_name, name, cname, parent_path); // TODO: REMOVE
|
||||
Hash *parent = getCArraysHash(parent_path, true);
|
||||
String *namespaces_tab = Getattr(parent, "namespaces");
|
||||
Printv(namespaces_tab, "&", cname, ",\n", NIL);
|
||||
|
|
@ -1945,7 +1919,7 @@ public:
|
|||
Delete(components);
|
||||
Delete(parent_path);
|
||||
} else if (!reg) // This namespace shouldn't be registered. Lets remember it.
|
||||
Setattr(carrays_hash, "lua:no_reg", "1");
|
||||
SetFlag(carrays_hash, "lua:no_reg");
|
||||
|
||||
Delete(mangled_name);
|
||||
mangled_name = 0;
|
||||
|
|
@ -1969,7 +1943,7 @@ public:
|
|||
assert(carrays_hash);
|
||||
assert(Getattr(carrays_hash, "lua:closed") == 0);
|
||||
|
||||
Setattr(carrays_hash, "lua:closed", "1");
|
||||
SetFlag(carrays_hash, "lua:closed");
|
||||
|
||||
String *attr_tab = Getattr(carrays_hash, "attributes");
|
||||
Printf(attr_tab, " {0,0,0}\n};\n");
|
||||
|
|
@ -1989,12 +1963,10 @@ public:
|
|||
}
|
||||
String *methods_tab = Getattr(carrays_hash, "methods");
|
||||
String *metatable_tab_name = Getattr(carrays_hash, "metatable:name");
|
||||
assert(methods_tab); // TODO: REMOVE
|
||||
if (elua_ltr || eluac_ltr) {
|
||||
if (v2_compatibility)
|
||||
Printv(methods_tab, tab4, "{LSTRKEY(\"const\"), LROVAL(", const_tab_name, ")},\n", NIL);
|
||||
if (elua_ltr) {
|
||||
assert(metatable_tab_name); // TODO: REMOVE
|
||||
Printv(methods_tab, tab4, "{LSTRKEY(\"__metatable\"), LROVAL(", metatable_tab_name, ")},\n", NIL);
|
||||
}
|
||||
|
||||
|
|
@ -2086,7 +2058,7 @@ public:
|
|||
void closeNamespaces(File *dataOutput) {
|
||||
// Special handling for empty module.
|
||||
if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
|
||||
// Module is empty. Create hash for global scope in order to have swig__Module
|
||||
// Module is empty. Create hash for global scope in order to have swig_SwigModule
|
||||
// variable in resulting file
|
||||
getCArraysHash(0);
|
||||
}
|
||||
|
|
@ -2177,6 +2149,9 @@ public:
|
|||
// If inside class, but current[NO_CPP], then this is friend function. It belongs to NSpace
|
||||
if (!getCurrentClass() || current[NO_CPP]) {
|
||||
scope = getNSpace();
|
||||
} else if (current[ENUM_CONST] && !CPlusPlus ) {
|
||||
// Enums in C mode go to NSpace
|
||||
scope = getNSpace();
|
||||
} else {
|
||||
// If inside class, then either class static namespace or class fully qualified name is used
|
||||
assert(!current[NO_CPP]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue