Cosmetic changes to lua.cxx after recent changes
This commit is contained in:
parent
d957d37636
commit
aaa71288b1
1 changed files with 91 additions and 82 deletions
|
|
@ -146,14 +146,14 @@ private:
|
||||||
// and is not visible to user in any manner. This variable holds the name
|
// 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
|
// of such pseudo-namespace a.k.a the result of above expression evaluation
|
||||||
String *class_static_nspace;
|
String *class_static_nspace;
|
||||||
// This variable holds the name of generated C function that acts as constructor
|
// This variable holds the name of generated C function that acts as a constructor
|
||||||
// for currently parsed class.
|
// for the currently parsed class.
|
||||||
String *constructor_name;
|
String *constructor_name;
|
||||||
|
|
||||||
// Many wrappers forward calls to each other, for example staticmembervariableHandler
|
// Many wrappers forward calls to each other, for example staticmembervariableHandler
|
||||||
// forwards call to variableHandler, which, in turn, makes to call to functionWrapper.
|
// forwards calls to variableHandler, which, in turn, makes to call to functionWrapper.
|
||||||
// In order to access information about whether it is static member of class or just
|
// In order to access information about whether it is a static member of class or just
|
||||||
// plain old variable an array current is kept and used as 'log' of call stack.
|
// a plain old variable, the current array is kept and used as a 'log' of the call stack.
|
||||||
enum TState {
|
enum TState {
|
||||||
NO_CPP,
|
NO_CPP,
|
||||||
VARIABLE,
|
VARIABLE,
|
||||||
|
|
@ -199,20 +199,7 @@ public:
|
||||||
for (int i = 0; i < STATES_COUNT; i++)
|
for (int i = 0; i < STATES_COUNT; i++)
|
||||||
current[i] = false;
|
current[i] = false;
|
||||||
}
|
}
|
||||||
~LUA() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool strToInt(const char *string, int &value) {
|
|
||||||
long int tmp;
|
|
||||||
char *p_end = 0;
|
|
||||||
if (string == 0)
|
|
||||||
return false;
|
|
||||||
tmp = strtol(string, &p_end, 10);
|
|
||||||
if (p_end == 0 || *p_end != 0)
|
|
||||||
return false;
|
|
||||||
value = tmp;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/* NEW LANGUAGE NOTE:***********************************************
|
/* NEW LANGUAGE NOTE:***********************************************
|
||||||
This is called to initalise the system & read any command line args
|
This is called to initalise the system & read any command line args
|
||||||
most of this is boilerplate code, except the command line args
|
most of this is boilerplate code, except the command line args
|
||||||
|
|
@ -259,7 +246,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elua_emulate && (eluac_ltr || elua_ltr )) {
|
if (elua_emulate && (eluac_ltr || elua_ltr )) {
|
||||||
Printf(stderr, "Can't have -elua-emulate and -eluac/-elua at the same time\n");
|
Printf(stderr, "Cannot have -elua-emulate with either -eluac or -elua\n");
|
||||||
Swig_arg_error();
|
Swig_arg_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,7 +387,7 @@ public:
|
||||||
Dump(f_wrappers, f_begin);
|
Dump(f_wrappers, f_begin);
|
||||||
Dump(f_initbeforefunc, f_begin);
|
Dump(f_initbeforefunc, f_begin);
|
||||||
/* for the Lua code it needs to be properly excaped to be added into the C/C++ code */
|
/* for the Lua code it needs to be properly excaped to be added into the C/C++ code */
|
||||||
EscapeCode(s_luacode);
|
escapeCode(s_luacode);
|
||||||
Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode);
|
Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode);
|
||||||
Wrapper_pretty_print(f_init, f_begin);
|
Wrapper_pretty_print(f_init, f_begin);
|
||||||
/* Close all of the files */
|
/* Close all of the files */
|
||||||
|
|
@ -426,13 +413,14 @@ public:
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* cDeclaration()
|
* cDeclaration()
|
||||||
* It copies sym:name to lua:name to preserve it's original value
|
* It copies sym:name to lua:name to preserve its 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
|
||||||
// the target language space, it is not true. sym:name and
|
// the target language space, it is not true. sym:name and
|
||||||
// it's derivatives are used in various places, including
|
// its derivatives are used in various places, including
|
||||||
// behind-the-scene C code generation. The best way is not to
|
// behind-the-scene C code generation. The best way is not to
|
||||||
// touch it at all.
|
// touch it at all.
|
||||||
// But we need to know what was the name of function/variable
|
// But we need to know what was the name of function/variable
|
||||||
|
|
@ -468,10 +456,11 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* registerMethod()
|
* registerMethod()
|
||||||
*
|
*
|
||||||
* Determines wrap name of a method, it's scope etc and calls
|
* Determines wrap name of a method, its scope etc and calls
|
||||||
* registerMethod overload with correct arguments
|
* registerMethod overload with correct arguments
|
||||||
* Overloaded variant adds method to the "methods" array of specified lua scope/class
|
* Overloaded variant adds method to the "methods" array of specified lua scope/class
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void registerMethod(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) {
|
void registerMethod(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) {
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
assert(symname);
|
assert(symname);
|
||||||
|
|
@ -479,8 +468,7 @@ public:
|
||||||
if (Getattr(n, "sym:nextSibling"))
|
if (Getattr(n, "sym:nextSibling"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Lua scope. It is not symbol NSpace, it is actuall key to revrieve
|
// Lua scope. It is not symbol NSpace, it is the actual key to retrieve getCArraysHash.
|
||||||
// getCArraysHash.
|
|
||||||
String *luaScope = luaCurrentSymbolNSpace();
|
String *luaScope = luaCurrentSymbolNSpace();
|
||||||
if (overwrite)
|
if (overwrite)
|
||||||
luaScope = overwriteLuaScope;
|
luaScope = overwriteLuaScope;
|
||||||
|
|
@ -490,12 +478,12 @@ public:
|
||||||
if (current[NO_CPP] || !getCurrentClass()) {
|
if (current[NO_CPP] || !getCurrentClass()) {
|
||||||
mrename = symname;
|
mrename = symname;
|
||||||
} else {
|
} else {
|
||||||
assert(!current[NO_CPP]);
|
assert(!current[NO_CPP]);
|
||||||
if (current[STATIC_FUNC] || current[MEMBER_FUNC]) {
|
if (current[STATIC_FUNC] || current[MEMBER_FUNC]) {
|
||||||
mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname);
|
mrename = Swig_name_member(getNSpace(), getClassPrefix(), symname);
|
||||||
} else {
|
} else {
|
||||||
mrename = symname;
|
mrename = symname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrapname = Swig_name_wrapper(mrename);
|
wrapname = Swig_name_wrapper(mrename);
|
||||||
//Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n",
|
//Printf(stdout, "luaname %s, symname %s mrename %s wrapname %s\n\tscope %s\n",
|
||||||
|
|
@ -503,7 +491,12 @@ public:
|
||||||
registerMethod(n, wrapname, luaScope);
|
registerMethod(n, wrapname, luaScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add method to the "methods" C array of given namespace/class
|
/* -----------------------------------------------------------------------
|
||||||
|
* registerMethod()
|
||||||
|
*
|
||||||
|
* Add method to the "methods" C array of given namespace/class
|
||||||
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void registerMethod(Node *n, String* wname, String *luaScope) {
|
void registerMethod(Node *n, String* wname, String *luaScope) {
|
||||||
assert(n);
|
assert(n);
|
||||||
Hash *nspaceHash = getCArraysHash(luaScope);
|
Hash *nspaceHash = getCArraysHash(luaScope);
|
||||||
|
|
@ -607,7 +600,7 @@ public:
|
||||||
this is the code to convert from the scripting language to C/C++
|
this is the code to convert from the scripting language to C/C++
|
||||||
some of the stuff will refer to the typemaps code written in your swig file
|
some of the stuff will refer to the typemaps code written in your swig file
|
||||||
(lua.swg), and some is done in the code here
|
(lua.swg), and some is done in the code here
|
||||||
I suppose you could do all the conversion on C, but it would be a nightmare to do
|
I suppose you could do all the conversion in C, but it would be a nightmare to do
|
||||||
NEW LANGUAGE NOTE:END *********************************************** */
|
NEW LANGUAGE NOTE:END *********************************************** */
|
||||||
/* Generate code for argument marshalling */
|
/* Generate code for argument marshalling */
|
||||||
// String *description = NewString("");
|
// String *description = NewString("");
|
||||||
|
|
@ -824,13 +817,7 @@ public:
|
||||||
NEW LANGUAGE NOTE:END *********************************************** */
|
NEW LANGUAGE NOTE:END *********************************************** */
|
||||||
/* Now register the function with the interpreter. */
|
/* Now register the function with the interpreter. */
|
||||||
int result = SWIG_OK;
|
int result = SWIG_OK;
|
||||||
if (!Getattr(n, "sym:overloaded")) {
|
if (Getattr(n, "sym:overloaded")) {
|
||||||
/* TODO: REMOVE
|
|
||||||
if (functionWrapperRegisterNow()) { // emit normal fns & static fns
|
|
||||||
registerMethod(n);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
if (!Getattr(n, "sym:nextSibling")) {
|
if (!Getattr(n, "sym:nextSibling")) {
|
||||||
result = dispatchFunction(n);
|
result = dispatchFunction(n);
|
||||||
}
|
}
|
||||||
|
|
@ -933,18 +920,18 @@ public:
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* Add variable to "attributes" C arrays of given namespace or class.
|
* Add variable to "attributes" C arrays of given namespace or class.
|
||||||
* Input is node. Base on the state of "current" array it determines
|
* Input is node. Based on the state of "current" array it determines
|
||||||
* the name of getter function, setter function etc and calls
|
* the name of the getter function, setter function etc and calls
|
||||||
* registeVariable overload with necessary params
|
* registerVariable overload with necessary params.
|
||||||
* Lua scope could be overwritten. (Used only for backward compatibility)
|
* Lua scope could be overwritten. (Used only for backward compatibility)
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
void registerVariable(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) {
|
void registerVariable(Node *n, bool overwrite = false, String *overwriteLuaScope = 0) {
|
||||||
int assignable = is_assignable(n);
|
int assignable = is_assignable(n);
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
assert(symname);
|
assert(symname);
|
||||||
|
|
||||||
// Lua scope. It is not symbol NSpace, it is actuall key to revrieve
|
// Lua scope. It is not symbol NSpace, it is the actual key to retrieve getCArraysHash.
|
||||||
// getCArraysHash.
|
|
||||||
String *luaScope = luaCurrentSymbolNSpace();
|
String *luaScope = luaCurrentSymbolNSpace();
|
||||||
if (overwrite)
|
if (overwrite)
|
||||||
luaScope = overwriteLuaScope;
|
luaScope = overwriteLuaScope;
|
||||||
|
|
@ -986,9 +973,10 @@ public:
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* registerVariable()
|
* registerVariable()
|
||||||
*
|
*
|
||||||
* Add variable to the "attributes" (or "get"/"set" in
|
* Add variable to the "attributes" (or "get"/"set" in
|
||||||
* case of elua_ltr) C arrays of given namespace or class
|
* case of elua_ltr) C arrays of given namespace or class
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
void registerVariable(String *lua_nspace_or_class_name, Node *n, String *getName, String *setName) {
|
void registerVariable(String *lua_nspace_or_class_name, Node *n, String *getName, String *setName) {
|
||||||
String *unassignable = NewString("SWIG_Lua_set_immutable");
|
String *unassignable = NewString("SWIG_Lua_set_immutable");
|
||||||
if (setName == 0 || GetFlag(n, "feature:immutable")) {
|
if (setName == 0 || GetFlag(n, "feature:immutable")) {
|
||||||
|
|
@ -1014,6 +1002,7 @@ public:
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* variableWrapper()
|
* 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
|
||||||
|
|
@ -1031,8 +1020,8 @@ public:
|
||||||
// TODO: REMOVE
|
// TODO: REMOVE
|
||||||
//registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name");
|
//registerVariable(luaCurrentSymbolNSpace(), n, "varget:wrap:name", "varset:wrap:name");
|
||||||
|
|
||||||
// It is impossible to use registerVariable, because sym:name of the Node is currenly
|
// It is impossible to use registerVariable, because sym:name of the Node is currently
|
||||||
// in undefined states - the callees of this function may have modified it.
|
// in an undefined state - the callees of this function may have modified it.
|
||||||
// registerVariable should be used from respective callees.*
|
// registerVariable should be used from respective callees.*
|
||||||
current[VARIABLE] = false;
|
current[VARIABLE] = false;
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1043,6 +1032,7 @@ public:
|
||||||
* 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 = getCArraysHash(nspace);
|
Hash *nspaceHash = getCArraysHash(nspace);
|
||||||
String *s_const_tab = 0;
|
String *s_const_tab = 0;
|
||||||
|
|
@ -1066,6 +1056,7 @@ public:
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* constantWrapper()
|
* 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");
|
||||||
|
|
@ -1235,9 +1226,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* Helper function that adds record to appropriate
|
* Helper function that adds record to appropriate C arrays
|
||||||
* C arrays
|
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
void registerClass(String *scope, String *wrap_class) {
|
void registerClass(String *scope, String *wrap_class) {
|
||||||
assert(wrap_class);
|
assert(wrap_class);
|
||||||
Hash *nspaceHash = getCArraysHash(scope);
|
Hash *nspaceHash = getCArraysHash(scope);
|
||||||
|
|
@ -1252,9 +1243,11 @@ public:
|
||||||
Printv(ns_methods, tab4, "{LSTRKEY(\"", proxy_class_name, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL);
|
Printv(ns_methods, tab4, "{LSTRKEY(\"", proxy_class_name, "\")", ", LROVAL(", cls_methods, ")", "},\n", NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* classHandler()
|
* classHandler()
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
virtual int classHandler(Node *n) {
|
virtual int classHandler(Node *n) {
|
||||||
//REPORT("classHandler", n);
|
//REPORT("classHandler", n);
|
||||||
|
|
||||||
|
|
@ -1275,7 +1268,7 @@ public:
|
||||||
proxy_class_name = Getattr(n, "sym:name");
|
proxy_class_name = Getattr(n, "sym:name");
|
||||||
// We have to enforce nspace here, because technically we are already
|
// We have to enforce nspace here, because technically we are already
|
||||||
// inside class parsing (getCurrentClass != 0), but we should register
|
// inside class parsing (getCurrentClass != 0), but we should register
|
||||||
// class in the it's parent namespace
|
// class in its parent namespace
|
||||||
if (!luaAddSymbol(proxy_class_name, n, nspace))
|
if (!luaAddSymbol(proxy_class_name, n, nspace))
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
|
|
||||||
|
|
@ -1578,18 +1571,20 @@ public:
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* globalfunctionHandler()
|
* globalfunctionHandler()
|
||||||
|
*
|
||||||
* It can be called:
|
* It can be called:
|
||||||
* 1. Usual C/C++ global function.
|
* 1. Usual C/C++ global function.
|
||||||
* 2. During class parsing for functions declared/defined as friend
|
* 2. During class parsing for functions declared/defined as friend
|
||||||
* 3. During class parsing from staticmemberfunctionHandler
|
* 3. During class parsing from staticmemberfunctionHandler
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int globalfunctionHandler(Node *n) {
|
virtual int globalfunctionHandler(Node *n) {
|
||||||
bool oldVal = current[NO_CPP];
|
bool oldVal = current[NO_CPP];
|
||||||
if (!current[STATIC_FUNC]) // If static funct, don't switch to NO_CPP
|
if (!current[STATIC_FUNC]) // If static function, don't switch to NO_CPP
|
||||||
current[NO_CPP] = true;
|
current[NO_CPP] = true;
|
||||||
const int result = Language::globalfunctionHandler(n);
|
const int result = Language::globalfunctionHandler(n);
|
||||||
|
|
||||||
if (!current[STATIC_FUNC]) // Register only if not called from static funct handler
|
if (!current[STATIC_FUNC]) // Register only if not called from static function handler
|
||||||
registerMethod(n);
|
registerMethod(n);
|
||||||
current[NO_CPP] = oldVal;
|
current[NO_CPP] = oldVal;
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1597,10 +1592,10 @@ public:
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* globalvariableHandler()
|
* globalvariableHandler()
|
||||||
* globalfunctionHandler()
|
*
|
||||||
* Sets "current" array correctly and calls
|
* Sets "current" array correctly
|
||||||
* Language::globalvariableHandler()
|
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int globalvariableHandler(Node *n) {
|
virtual int globalvariableHandler(Node *n) {
|
||||||
bool oldVal = current[NO_CPP];
|
bool oldVal = current[NO_CPP];
|
||||||
current[GLOBAL_VAR] = true;
|
current[GLOBAL_VAR] = true;
|
||||||
|
|
@ -1631,9 +1626,9 @@ public:
|
||||||
if (v2_compatibility && result == SWIG_OK) {
|
if (v2_compatibility && result == SWIG_OK) {
|
||||||
Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL);
|
Swig_require("lua_staticmemberfunctionHandler", n, "*lua:name", NIL);
|
||||||
String *lua_name = Getattr(n, "lua:name");
|
String *lua_name = Getattr(n, "lua:name");
|
||||||
// Although this function uses Swig_name_member, it actually generateds Lua name,
|
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
||||||
// not C++ name. It is because previous version used such scheme for static func
|
// 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
|
// name generation and we have to maintain backward compatibility.
|
||||||
String *compat_name = Swig_name_member(0, proxy_class_name, lua_name);
|
String *compat_name = Swig_name_member(0, proxy_class_name, lua_name);
|
||||||
Setattr(n, "lua:name", compat_name);
|
Setattr(n, "lua:name", compat_name);
|
||||||
registerMethod(n, true, getNSpace());
|
registerMethod(n, true, getNSpace());
|
||||||
|
|
@ -1676,9 +1671,9 @@ public:
|
||||||
if (v2_compatibility) {
|
if (v2_compatibility) {
|
||||||
Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL);
|
Swig_save("lua_staticmembervariableHandler", n, "lua:name", NIL);
|
||||||
String *lua_name = Getattr(n, "lua:name");
|
String *lua_name = Getattr(n, "lua:name");
|
||||||
// Although this function uses Swig_name_member, it actually generateds Lua name,
|
// Although this function uses Swig_name_member, it actually generates the Lua name,
|
||||||
// not C++ name. It is because previous version used such scheme for static vars
|
// 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
|
// name generation and we have to maintain backward compatibility.
|
||||||
String *v2_name = Swig_name_member(NIL, proxy_class_name, lua_name);
|
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
|
//Printf( stdout, "Name %s, class %s, compt. name %s\n", lua_name, proxy_class_name, v2_name ); // TODO: REMOVE
|
||||||
if (!GetFlag(n, "wrappedasconstant")) {
|
if (!GetFlag(n, "wrappedasconstant")) {
|
||||||
|
|
@ -1686,9 +1681,8 @@ public:
|
||||||
// Registering static var in the class parent nspace
|
// Registering static var in the class parent nspace
|
||||||
registerVariable(n, true, getNSpace());
|
registerVariable(n, true, getNSpace());
|
||||||
}
|
}
|
||||||
// If static member variable was wrapped as constant, then
|
// If static member variable was wrapped as a constant, then
|
||||||
// constant wrapper has already performed all actions
|
// constant wrapper has already performed all actions necessary for v2_compatibility
|
||||||
// necessary for v2_compatibility
|
|
||||||
Delete(v2_name);
|
Delete(v2_name);
|
||||||
Swig_restore(n);
|
Swig_restore(n);
|
||||||
}
|
}
|
||||||
|
|
@ -1753,12 +1747,14 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* EscapeCode()
|
* escapeCode()
|
||||||
|
*
|
||||||
* This is to convert the string of Lua code into a proper string, which can then be
|
* This is to convert the string of Lua code into a proper string, which can then be
|
||||||
* emitted into the C/C++ code.
|
* emitted into the C/C++ code.
|
||||||
* Basically is is a lot of search & replacing of odd sequences
|
* 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
|
||||||
Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first)
|
Replace(str, "\\", "\\\\", DOH_REPLACE_ANY); // \ to \\ (this must be done first)
|
||||||
|
|
@ -1772,6 +1768,7 @@ public:
|
||||||
*
|
*
|
||||||
* A small helper to hide impelementation of how CArrays hashes are stored
|
* A small helper to hide impelementation of how CArrays hashes are stored
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Hash *rawGetCArraysHash(const_String_or_char_ptr name) {
|
Hash *rawGetCArraysHash(const_String_or_char_ptr name) {
|
||||||
Hash *scope = symbolScopeLookup( name ? name : "" );
|
Hash *scope = symbolScopeLookup( name ? name : "" );
|
||||||
if(!scope)
|
if(!scope)
|
||||||
|
|
@ -1783,20 +1780,22 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* getCArraysHash()
|
* getCArraysHash()
|
||||||
* Each namespace can be described with hash that stores C arrays
|
*
|
||||||
|
* Each namespace can be described with a hash that stores C arrays
|
||||||
* where members of the namespace should be added. All these hashes are stored
|
* where members of the namespace should be added. All these hashes are stored
|
||||||
* inside symbols table, in pseudo-symbol for every namespace.
|
* inside the symbols table, in pseudo-symbol for every namespace.
|
||||||
* nspace could be NULL (NSPACE_TODO), that means functions and variables and classes
|
* 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)
|
* 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:
|
* 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_namespaces" will disable "namespaces" array.
|
||||||
* "lua:no_classes" will disable "classes" array.
|
* "lua:no_classes" will disable "classes" array.
|
||||||
* For every component ("attributes", "methods", etc) there are subcomponents:
|
* For every component ("attributes", "methods", etc) there are subcomponents:
|
||||||
* XXX:name - name of the C array that stores data for component
|
* XXX:name - name of the C array that stores data for component
|
||||||
* XXX:decl - statement with forward declaration of this array;
|
* 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
|
* Namespace could be automatically registered to its parent if 'reg' == true. This can only be
|
||||||
* only at first call (a.k.a when nspace is created).
|
* done during the first call (a.k.a when nspace is created).
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Hash *getCArraysHash(String *nspace, bool reg = true) {
|
Hash *getCArraysHash(String *nspace, bool reg = true) {
|
||||||
Hash *scope = symbolScopeLookup(nspace ? nspace : "");
|
Hash *scope = symbolScopeLookup(nspace ? nspace : "");
|
||||||
if(!scope) {
|
if(!scope) {
|
||||||
|
|
@ -1945,10 +1944,9 @@ public:
|
||||||
|
|
||||||
Delete(components);
|
Delete(components);
|
||||||
Delete(parent_path);
|
Delete(parent_path);
|
||||||
} else if (!reg) // This namespace shouldn't be registered. Lets remember it
|
} else if (!reg) // This namespace shouldn't be registered. Lets remember it.
|
||||||
Setattr(carrays_hash, "lua:no_reg", "1");
|
Setattr(carrays_hash, "lua:no_reg", "1");
|
||||||
|
|
||||||
|
|
||||||
Delete(mangled_name);
|
Delete(mangled_name);
|
||||||
mangled_name = 0;
|
mangled_name = 0;
|
||||||
return carrays_hash;
|
return carrays_hash;
|
||||||
|
|
@ -1956,14 +1954,16 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* closeCArraysHash()
|
* closeCArraysHash()
|
||||||
|
*
|
||||||
* Functions add end markers {0,0,...,0} to all arrays, prints them to
|
* 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 the same hash will result in an error.
|
||||||
* closeCArraysHash DOES NOT print structure that describes namespace, it only
|
* closeCArraysHash DOES NOT print structure that describes namespace, it only
|
||||||
* prints array. You can use printCArraysDefinition to print structure.
|
* prints array. You can use printCArraysDefinition 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 closeCArraysHash(String *nspace, File *output) {
|
void closeCArraysHash(String *nspace, File *output) {
|
||||||
Hash *carrays_hash = rawGetCArraysHash(nspace);
|
Hash *carrays_hash = rawGetCArraysHash(nspace);
|
||||||
assert(carrays_hash);
|
assert(carrays_hash);
|
||||||
|
|
@ -2078,9 +2078,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* closeCArraysHash()
|
* closeNamespaces()
|
||||||
|
*
|
||||||
* Recursively close all non-closed namespaces. Prints data to dataOutput.
|
* 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 (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
|
if (symbolScopeLookup("") == 0 || rawGetCArraysHash("") == 0) {
|
||||||
|
|
@ -2124,13 +2126,14 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* printCArraysDefinition()
|
* printCArraysDefinition()
|
||||||
* This function prints to output a definition of namespace in
|
*
|
||||||
* form
|
* This function prints to output a definition of namespace in form
|
||||||
* swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array };
|
* swig_lua_namespace $cname = { attr_array, methods_array, ... , namespaces_array };
|
||||||
* You can call this function as many times as necessary.
|
* You can call this function as many times as is necessary.
|
||||||
* 'name' is a user-visible name that this namespace will have in Lua. It shouldn't
|
* '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.
|
* be a fully qualified name, just its own name.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void printCArraysDefinition(String *nspace, String *name, File *output) {
|
void printCArraysDefinition(String *nspace, String *name, File *output) {
|
||||||
Hash *carrays_hash = getCArraysHash(nspace, false);
|
Hash *carrays_hash = getCArraysHash(nspace, false);
|
||||||
|
|
||||||
|
|
@ -2159,6 +2162,7 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* luaCurrentSymbolNSpace()
|
* luaCurrentSymbolNSpace()
|
||||||
|
*
|
||||||
* This function determines actual namespace/scope where any symbol at the
|
* This function determines actual namespace/scope where any symbol at the
|
||||||
* current moment should be placed. It looks at the 'current' array
|
* current moment should be placed. It looks at the 'current' array
|
||||||
* and depending on where are we - static class member/function,
|
* and depending on where are we - static class member/function,
|
||||||
|
|
@ -2166,6 +2170,7 @@ public:
|
||||||
* where symbol should be put.
|
* where symbol should be put.
|
||||||
* The namespace/scope doesn't depend from symbol, only from 'current'
|
* 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.
|
||||||
|
|
@ -2190,9 +2195,11 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* luaAddSymbol()
|
* luaAddSymbol()
|
||||||
|
*
|
||||||
* Our implementation of addSymbol. Determines scope correctly, then
|
* Our implementation of addSymbol. Determines scope correctly, then
|
||||||
* forwards to Language::addSymbol
|
* forwards to Language::addSymbol
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int luaAddSymbol(const String *s, const Node *n) {
|
int luaAddSymbol(const String *s, const Node *n) {
|
||||||
String *scope = luaCurrentSymbolNSpace();
|
String *scope = luaCurrentSymbolNSpace();
|
||||||
return luaAddSymbol(s, n, scope);
|
return luaAddSymbol(s, n, scope);
|
||||||
|
|
@ -2200,8 +2207,10 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* luaAddSymbol()
|
* luaAddSymbol()
|
||||||
|
*
|
||||||
* Overload. Enforces given scope. Actually, it simply forwards call to Language::addSymbol
|
* 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) {
|
||||||
int result = Language::addSymbol(s, n, scope);
|
int result = Language::addSymbol(s, n, scope);
|
||||||
if (!result)
|
if (!result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue