|
|
@@ -71,22 +71,33 @@ string Generator::getIdentifier(string refId)
|
|
|
return refId;
|
|
|
}
|
|
|
|
|
|
-string Generator::getClassNameWithoutNamespace(string classname)
|
|
|
+string Generator::getClassNameAndNamespace(string classname, string* ns)
|
|
|
{
|
|
|
size_t index = classname.find("::");
|
|
|
if (index != classname.npos)
|
|
|
{
|
|
|
- string ns = classname.substr(0, index);
|
|
|
- if (_namespaces.find(ns) != _namespaces.end())
|
|
|
+ string classNS = classname.substr(0, index);
|
|
|
+ if (_namespaces.find(classNS) != _namespaces.end())
|
|
|
{
|
|
|
- string tmp = classname.substr(index + 2);
|
|
|
- size_t tmpIndex = tmp.find("::");
|
|
|
- if (tmpIndex != tmp.npos)
|
|
|
- tmp = tmp.substr(0, tmpIndex);
|
|
|
+ if (ns)
|
|
|
+ *ns = classNS;
|
|
|
|
|
|
- tmp = ns + string("::") + tmp;
|
|
|
- if (find(_namespaces[ns].begin(), _namespaces[ns].end(), tmp) != _namespaces[ns].end())
|
|
|
+ string tmp = classname.substr(index + 2);
|
|
|
+ if (_namespaces[classNS].find(tmp) != _namespaces[classNS].end())
|
|
|
return classname.substr(index + 2);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ size_t tmpIndex = tmp.find("::");
|
|
|
+ if (tmpIndex != tmp.npos)
|
|
|
+ {
|
|
|
+ tmp = tmp.substr(0, tmpIndex);
|
|
|
+ if (_namespaces[classNS].find(tmp) != _namespaces[classNS].end())
|
|
|
+ {
|
|
|
+ _namespaces[classNS].insert(classname.substr(index + 2));
|
|
|
+ return classname.substr(index + 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -150,7 +161,7 @@ string Generator::getCompoundName(XMLElement* node)
|
|
|
return string(text);
|
|
|
}
|
|
|
|
|
|
-void Generator::run(string inDir, string outDir)
|
|
|
+void Generator::run(string inDir, string outDir, string* bindingNS)
|
|
|
{
|
|
|
// Set the output directory.
|
|
|
_outDir = outDir;
|
|
|
@@ -248,7 +259,7 @@ void Generator::run(string inDir, string outDir)
|
|
|
resolveInheritedIncludes();
|
|
|
|
|
|
// Generate the script bindings.
|
|
|
- generateBindings();
|
|
|
+ generateBindings(bindingNS);
|
|
|
|
|
|
// Print out all warnings (unsupported types, function name-Lua keyword clashes, etc.)
|
|
|
if (__warnings.size() > 0)
|
|
|
@@ -277,7 +288,7 @@ Generator::~Generator()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-void Generator::getFunctions(XMLElement* fileNode)
|
|
|
+void Generator::getFunctions(XMLElement* fileNode, string ns)
|
|
|
{
|
|
|
// Process all public, non-static functions and variables that are defined in this file.
|
|
|
XMLElement* node = NULL;
|
|
|
@@ -313,6 +324,10 @@ void Generator::getFunctions(XMLElement* fileNode)
|
|
|
getParams(e, b);
|
|
|
getCreateFlag(e, b);
|
|
|
_functions[b.getFunctionName()].push_back(b);
|
|
|
+
|
|
|
+ // Add the function to the set of namespace members if it is part of a namespace.
|
|
|
+ if (ns.size() > 0)
|
|
|
+ _namespaces[ns].insert(b.name);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -347,6 +362,10 @@ void Generator::getFunctions(XMLElement* fileNode)
|
|
|
{
|
|
|
b.returnParam = getParam(e, true);
|
|
|
_functions[b.getFunctionName()].push_back(b);
|
|
|
+
|
|
|
+ // Add the variable to the set of namespace members if it is part of a namespace.
|
|
|
+ if (ns.size() > 0)
|
|
|
+ _namespaces[ns].insert(b.name);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -365,23 +384,26 @@ void Generator::getNamespace(XMLElement* nsNode, const string& name)
|
|
|
if (name == "std")
|
|
|
return;
|
|
|
|
|
|
- // Create a list of all classes that are a part of this namespace.
|
|
|
+ // Create the set of all classes that are a part of this namespace.
|
|
|
XMLElement* e = nsNode->FirstChildElement("innerclass");
|
|
|
while (e)
|
|
|
{
|
|
|
- _namespaces[name].push_back(e->GetText());
|
|
|
+ string classname = e->GetText();
|
|
|
+ size_t i = classname.find("::");
|
|
|
+ if (i != classname.npos)
|
|
|
+ classname = classname.substr(i + 2);
|
|
|
+ _namespaces[name].insert(classname);
|
|
|
e = e->NextSiblingElement("innerclass");
|
|
|
}
|
|
|
|
|
|
// Parse all functions that are directly in this namespace.
|
|
|
- getFunctions(nsNode);
|
|
|
+ getFunctions(nsNode, name);
|
|
|
|
|
|
// Parse all enums that are directly in this namespace.
|
|
|
getEnums(nsNode, name);
|
|
|
|
|
|
// Parse all typedefs.
|
|
|
getTypedefs(nsNode, name);
|
|
|
- e = nsNode->FirstChildElement("");
|
|
|
}
|
|
|
|
|
|
void Generator::getClass(XMLElement* classNode, const string& name)
|
|
|
@@ -787,6 +809,10 @@ void Generator::getEnum(XMLElement* e, string classname, string ns, string inclu
|
|
|
{
|
|
|
_enums[enumname].values.push_back(getName(e));
|
|
|
}
|
|
|
+
|
|
|
+ // Add the enum to the set of namespace members if it is part of a namespace.
|
|
|
+ if (ns.size() > 0)
|
|
|
+ _namespaces[ns].insert(enumname);
|
|
|
}
|
|
|
|
|
|
void Generator::getTypedefs(XMLElement* fileNode, string ns)
|
|
|
@@ -828,9 +854,6 @@ void Generator::getTypedef(XMLElement* e, string classname, string ns)
|
|
|
tname += string("::");
|
|
|
tname += getName(e);
|
|
|
|
|
|
- if (!REMOVE_NAMESPACE)
|
|
|
- tname = ns + string("::") + tname;
|
|
|
-
|
|
|
// Get the typedef's id and store the mapping from ref id to name.
|
|
|
string refId = e->Attribute("id");
|
|
|
setIdentifier(refId, tname);
|
|
|
@@ -840,6 +863,10 @@ void Generator::getTypedef(XMLElement* e, string classname, string ns)
|
|
|
t.refId = p.info;
|
|
|
|
|
|
_typedefs[tname] = t;
|
|
|
+
|
|
|
+ // Add the typedef to the set of namespace members if it is part of a namespace.
|
|
|
+ if (ns.size() > 0)
|
|
|
+ _namespaces[ns].insert(tname);
|
|
|
}
|
|
|
|
|
|
static inline bool getScriptFlagHelper(XMLElement* e, string& flag)
|
|
|
@@ -1336,10 +1363,12 @@ void Generator::resolveTypes()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Generator::generateBindings()
|
|
|
+void Generator::generateBindings(string* bindingNS)
|
|
|
{
|
|
|
- string* bindingNS = new string("gameplay");
|
|
|
-
|
|
|
+ bool generatingGameplay = false;
|
|
|
+ if (bindingNS && (*bindingNS == "gameplay"))
|
|
|
+ generatingGameplay = true;
|
|
|
+
|
|
|
string luaAllHStr = _outDir + string(LUA_ALL_BINDINGS_FILENAME) + string(".h");
|
|
|
ofstream luaAllH(luaAllHStr.c_str());
|
|
|
string includeGuard = string(LUA_ALL_BINDINGS_FILENAME) + string("_H_");
|
|
|
@@ -1365,11 +1394,14 @@ void Generator::generateBindings()
|
|
|
map<string, ClassBinding>::iterator iter = _classes.begin();
|
|
|
for (; iter != _classes.end(); iter++)
|
|
|
{
|
|
|
- cout << "Generating bindings for '" << iter->first << "'...\n";
|
|
|
- iter->second.write(_outDir, _includes[iter->second.include], bindingNS);
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->second.classname) == _namespaces["gameplay"].end()))
|
|
|
+ {
|
|
|
+ cout << "Generating bindings for '" << iter->first << "'...\n";
|
|
|
+ iter->second.write(_outDir, _includes[iter->second.include], bindingNS);
|
|
|
|
|
|
- luaAllH << "#include \"lua_" << iter->second.uniquename << ".h\"\n";
|
|
|
- luaAllCpp << " luaRegister_" << iter->second.uniquename << "();\n";
|
|
|
+ luaAllH << "#include \"lua_" << iter->second.uniquename << ".h\"\n";
|
|
|
+ luaAllCpp << " luaRegister_" << iter->second.uniquename << "();\n";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1387,118 +1419,123 @@ void Generator::generateBindings()
|
|
|
// Write out the enum conversion function declarations.
|
|
|
for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
{
|
|
|
- // Header.
|
|
|
- string enumHStr = _outDir + string("lua_") + getUniqueName(iter->first) + string(".h");
|
|
|
- ofstream enumH(enumHStr.c_str());
|
|
|
- includeGuard = string("lua_") + getUniqueName(iter->first) + string("_H_");
|
|
|
- transform(includeGuard.begin(), includeGuard.end(), includeGuard.begin(), ::toupper);
|
|
|
- enumH << "#ifndef " << includeGuard << "\n";
|
|
|
- enumH << "#define " << includeGuard << "\n\n";
|
|
|
- enumH << "#include \"" << iter->second.include << "\"\n\n";
|
|
|
-
|
|
|
- if (bindingNS)
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->first) == _namespaces["gameplay"].end()))
|
|
|
{
|
|
|
- enumH << "namespace " << *bindingNS << "\n";
|
|
|
- enumH << "{\n\n";
|
|
|
- }
|
|
|
+ cout << "Generating bindings for '" << iter->first << "'...\n";
|
|
|
+
|
|
|
+ // Header.
|
|
|
+ string enumHStr = _outDir + string("lua_") + getUniqueName(iter->first) + string(".h");
|
|
|
+ ofstream enumH(enumHStr.c_str());
|
|
|
+ includeGuard = string("lua_") + getUniqueName(iter->first) + string("_H_");
|
|
|
+ transform(includeGuard.begin(), includeGuard.end(), includeGuard.begin(), ::toupper);
|
|
|
+ enumH << "#ifndef " << includeGuard << "\n";
|
|
|
+ enumH << "#define " << includeGuard << "\n\n";
|
|
|
+ enumH << "#include \"" << iter->second.include << "\"\n\n";
|
|
|
+
|
|
|
+ if (bindingNS)
|
|
|
+ {
|
|
|
+ enumH << "namespace " << *bindingNS << "\n";
|
|
|
+ enumH << "{\n\n";
|
|
|
+ }
|
|
|
|
|
|
- enumH << "// Lua bindings for enum conversion functions for " << iter->first << ".\n";
|
|
|
- enumH << iter->first << " lua_enumFromString_" << getUniqueName(iter->first) << "(const char* s);\n";
|
|
|
- enumH << "const char* lua_stringFromEnum_" << getUniqueName(iter->first) << "(" << iter->first << " e);\n\n";
|
|
|
+ enumH << "// Lua bindings for enum conversion functions for " << iter->first << ".\n";
|
|
|
+ enumH << iter->first << " lua_enumFromString_" << getUniqueName(iter->first) << "(const char* s);\n";
|
|
|
+ enumH << "const char* lua_stringFromEnum_" << getUniqueName(iter->first) << "(" << iter->first << " e);\n\n";
|
|
|
|
|
|
- if (bindingNS)
|
|
|
- {
|
|
|
- enumH << "}\n\n";
|
|
|
- }
|
|
|
+ if (bindingNS)
|
|
|
+ {
|
|
|
+ enumH << "}\n\n";
|
|
|
+ }
|
|
|
|
|
|
- enumH << "#endif\n";
|
|
|
- enumH.close();
|
|
|
+ enumH << "#endif\n";
|
|
|
+ enumH.close();
|
|
|
|
|
|
- // Implementation.
|
|
|
- string enumCppStr = _outDir + string("lua_") + getUniqueName(iter->first) + string(".cpp");
|
|
|
- ofstream enumCpp(enumCppStr.c_str());
|
|
|
- enumCpp << "#include \"Base.h\"\n";
|
|
|
- enumCpp << "#include \"lua_" << getUniqueName(iter->first) << ".h\"\n\n";
|
|
|
+ // Implementation.
|
|
|
+ string enumCppStr = _outDir + string("lua_") + getUniqueName(iter->first) + string(".cpp");
|
|
|
+ ofstream enumCpp(enumCppStr.c_str());
|
|
|
+ enumCpp << "#include \"Base.h\"\n";
|
|
|
+ enumCpp << "#include \"lua_" << getUniqueName(iter->first) << ".h\"\n\n";
|
|
|
|
|
|
- if (bindingNS)
|
|
|
- {
|
|
|
- enumCpp << "namespace " << *bindingNS << "\n";
|
|
|
- enumCpp << "{\n\n";
|
|
|
- }
|
|
|
+ if (bindingNS)
|
|
|
+ {
|
|
|
+ enumCpp << "namespace " << *bindingNS << "\n";
|
|
|
+ enumCpp << "{\n\n";
|
|
|
+ }
|
|
|
|
|
|
- enumCpp << "static const char* enumStringEmpty = \"\";\n\n";
|
|
|
+ enumCpp << "static const char* enumStringEmpty = \"\";\n\n";
|
|
|
|
|
|
- // Build the scope string if applicable.
|
|
|
- string scope;
|
|
|
- if (iter->second.scopePath.size() > 0)
|
|
|
- {
|
|
|
- for (unsigned int i = 0; i < iter->second.scopePath.size(); i++)
|
|
|
+ // Build the scope string if applicable.
|
|
|
+ string scope;
|
|
|
+ if (iter->second.scopePath.size() > 0)
|
|
|
{
|
|
|
- scope += iter->second.scopePath[i] + string("::");
|
|
|
+ for (unsigned int i = 0; i < iter->second.scopePath.size(); i++)
|
|
|
+ {
|
|
|
+ scope += iter->second.scopePath[i] + string("::");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // Write out the string constants that correspond to the enumeration values.
|
|
|
- for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
- {
|
|
|
- enumCpp << "static const char* luaEnumString_" << getUniqueName(iter->first) << "_";
|
|
|
- enumCpp << iter->second.values[i] << " = \"" << iter->second.values[i] << "\";\n";
|
|
|
- }
|
|
|
- enumCpp << "\n";
|
|
|
+ // Write out the string constants that correspond to the enumeration values.
|
|
|
+ for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
+ {
|
|
|
+ enumCpp << "static const char* luaEnumString_" << getUniqueName(iter->first) << "_";
|
|
|
+ enumCpp << iter->second.values[i] << " = \"" << iter->second.values[i] << "\";\n";
|
|
|
+ }
|
|
|
+ enumCpp << "\n";
|
|
|
|
|
|
- enumCpp << iter->first << " lua_enumFromString_" << getUniqueName(iter->first) << "(const char* s)\n";
|
|
|
- enumCpp << "{\n";
|
|
|
+ enumCpp << iter->first << " lua_enumFromString_" << getUniqueName(iter->first) << "(const char* s)\n";
|
|
|
+ enumCpp << "{\n";
|
|
|
|
|
|
- for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
- {
|
|
|
- enumCpp << " ";
|
|
|
-
|
|
|
- enumCpp << "if (strcmp(s, luaEnumString_" << getUniqueName(iter->first) << "_" << iter->second.values[i] << ") == 0)\n";
|
|
|
- enumCpp << " return ";
|
|
|
- if (scope.size() > 0)
|
|
|
- enumCpp << scope;
|
|
|
- enumCpp << iter->second.values[i] << ";\n";
|
|
|
-
|
|
|
- if (i == iter->second.values.size() - 1)
|
|
|
+ for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
{
|
|
|
- enumCpp << " GP_ERROR(\"Invalid enumeration value '%s' for enumeration " << iter->first << ".\", s);\n";
|
|
|
- enumCpp << " return ";
|
|
|
+ enumCpp << " ";
|
|
|
+
|
|
|
+ enumCpp << "if (strcmp(s, luaEnumString_" << getUniqueName(iter->first) << "_" << iter->second.values[i] << ") == 0)\n";
|
|
|
+ enumCpp << " return ";
|
|
|
if (scope.size() > 0)
|
|
|
enumCpp << scope;
|
|
|
- enumCpp << iter->second.values[0] << ";\n";
|
|
|
+ enumCpp << iter->second.values[i] << ";\n";
|
|
|
+
|
|
|
+ if (i == iter->second.values.size() - 1)
|
|
|
+ {
|
|
|
+ enumCpp << " GP_ERROR(\"Invalid enumeration value '%s' for enumeration " << iter->first << ".\", s);\n";
|
|
|
+ enumCpp << " return ";
|
|
|
+ if (scope.size() > 0)
|
|
|
+ enumCpp << scope;
|
|
|
+ enumCpp << iter->second.values[0] << ";\n";
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- enumCpp << "}\n\n";
|
|
|
+ enumCpp << "}\n\n";
|
|
|
|
|
|
- enumCpp << "const char* lua_stringFromEnum_" << getUniqueName(iter->first) << "(" << iter->first << " e)\n";
|
|
|
- enumCpp << "{\n";
|
|
|
+ enumCpp << "const char* lua_stringFromEnum_" << getUniqueName(iter->first) << "(" << iter->first << " e)\n";
|
|
|
+ enumCpp << "{\n";
|
|
|
|
|
|
- // Write out the enum-to-string conversion code.
|
|
|
- for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
- {
|
|
|
- enumCpp << " ";
|
|
|
+ // Write out the enum-to-string conversion code.
|
|
|
+ for (unsigned int i = 0; i < iter->second.values.size(); i++)
|
|
|
+ {
|
|
|
+ enumCpp << " ";
|
|
|
|
|
|
- enumCpp << "if (e == ";
|
|
|
- if (scope.size() > 0)
|
|
|
- enumCpp << scope;
|
|
|
- enumCpp << iter->second.values[i] << ")\n";
|
|
|
- enumCpp << " return luaEnumString_" << getUniqueName(iter->first) << "_" << iter->second.values[i] << ";\n";
|
|
|
+ enumCpp << "if (e == ";
|
|
|
+ if (scope.size() > 0)
|
|
|
+ enumCpp << scope;
|
|
|
+ enumCpp << iter->second.values[i] << ")\n";
|
|
|
+ enumCpp << " return luaEnumString_" << getUniqueName(iter->first) << "_" << iter->second.values[i] << ";\n";
|
|
|
|
|
|
- if (i == iter->second.values.size() - 1)
|
|
|
- {
|
|
|
- enumCpp << " GP_ERROR(\"Invalid enumeration value '%d' for enumeration " << iter->first << ".\", e);\n";
|
|
|
- enumCpp << " return enumStringEmpty;\n";
|
|
|
+ if (i == iter->second.values.size() - 1)
|
|
|
+ {
|
|
|
+ enumCpp << " GP_ERROR(\"Invalid enumeration value '%d' for enumeration " << iter->first << ".\", e);\n";
|
|
|
+ enumCpp << " return enumStringEmpty;\n";
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- enumCpp << "}\n\n";
|
|
|
-
|
|
|
- if (bindingNS)
|
|
|
- {
|
|
|
enumCpp << "}\n\n";
|
|
|
+
|
|
|
+ if (bindingNS)
|
|
|
+ {
|
|
|
+ enumCpp << "}\n\n";
|
|
|
+ }
|
|
|
+ enumCpp.close();
|
|
|
}
|
|
|
- enumCpp.close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1506,6 +1543,34 @@ void Generator::generateBindings()
|
|
|
cout << "Generating global bindings...\n";
|
|
|
if (baseClasses.size() > 0 || _functions.size() > 0 || _enums.size() > 0)
|
|
|
{
|
|
|
+ // Calculate if there are global function bindings to write out.
|
|
|
+ bool generateGlobalFunctionBindings = false;
|
|
|
+ if (_functions.size() > 0)
|
|
|
+ {
|
|
|
+ for (map<string, vector<FunctionBinding> >::iterator iter = _functions.begin(); iter != _functions.end(); iter++)
|
|
|
+ {
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->second[0].name) == _namespaces["gameplay"].end()))
|
|
|
+ {
|
|
|
+ generateGlobalFunctionBindings = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Calculate if there are enum bindings to write out.
|
|
|
+ bool generateEnumBindings = false;
|
|
|
+ if (_enums.size() > 0)
|
|
|
+ {
|
|
|
+ for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
+ {
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->first) == _namespaces["gameplay"].end()))
|
|
|
+ {
|
|
|
+ generateEnumBindings = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Write out the header file.
|
|
|
{
|
|
|
string path = _outDir + string(LUA_GLOBAL_FILENAME) + string(".h");
|
|
|
@@ -1518,7 +1583,8 @@ void Generator::generateBindings()
|
|
|
// Write out the needed includes for the global enumeration function.
|
|
|
for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
{
|
|
|
- global << "#include \"lua_" << getUniqueName(iter->first) << ".h\"\n";
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->first) == _namespaces["gameplay"].end()))
|
|
|
+ global << "#include \"lua_" << getUniqueName(iter->first) << ".h\"\n";
|
|
|
}
|
|
|
global << "\n";
|
|
|
luaAllH << "#include \"" << string(LUA_GLOBAL_FILENAME) << ".h\"\n";
|
|
|
@@ -1530,19 +1596,20 @@ void Generator::generateBindings()
|
|
|
global << "{\n\n";
|
|
|
}
|
|
|
|
|
|
- if (_functions.size() > 0)
|
|
|
+ if (generateGlobalFunctionBindings)
|
|
|
{
|
|
|
global << "// Lua bindings for global functions.\n";
|
|
|
|
|
|
// Write out the binding function declarations.
|
|
|
for (map<string, vector<FunctionBinding> >::iterator iter = _functions.begin(); iter != _functions.end(); iter++)
|
|
|
{
|
|
|
- global << "int " << iter->second[0].getFunctionName() << "(lua_State* state);\n";
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->second[0].name) == _namespaces["gameplay"].end()))
|
|
|
+ global << "int " << iter->second[0].getFunctionName() << "(lua_State* state);\n";
|
|
|
}
|
|
|
global << "\n";
|
|
|
}
|
|
|
|
|
|
- if (_enums.size() > 0)
|
|
|
+ if (generateEnumBindings)
|
|
|
{
|
|
|
global << "// Global enum to string conversion function (used to pass enums to Lua from C++).\n";
|
|
|
global << "const char* lua_stringFromEnumGlobal(std::string& enumname, unsigned int value);\n\n";
|
|
|
@@ -1584,77 +1651,94 @@ void Generator::generateBindings()
|
|
|
global << "void luaRegister_" << LUA_GLOBAL_FILENAME << "()\n";
|
|
|
global << "{\n";
|
|
|
|
|
|
- if (_functions.size() > 0)
|
|
|
+ if (generateGlobalFunctionBindings)
|
|
|
{
|
|
|
- global << "\n";
|
|
|
// Bind the non-member functions.
|
|
|
for (map<string, vector<FunctionBinding> >::iterator iter = _functions.begin(); iter != _functions.end(); iter++)
|
|
|
{
|
|
|
- global << " ScriptUtil::registerFunction(\"" << iter->second[0].name << "\", " << iter->second[0].getFunctionName() << ");\n";
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->second[0].name) == _namespaces["gameplay"].end()))
|
|
|
+ global << " ScriptUtil::registerFunction(\"" << iter->second[0].name << "\", " << iter->second[0].getFunctionName() << ");\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Generate the hierarchy map.
|
|
|
if (baseClasses.size() > 0)
|
|
|
{
|
|
|
- global << "\n std::map<std::string, std::vector<std::string> > hierarchy;\n";
|
|
|
for (unsigned int i = 0, count = baseClasses.size(); i < count; i++)
|
|
|
{
|
|
|
set<string> derived;
|
|
|
getAllDerived(derived, baseClasses[i]);
|
|
|
for (set<string>::iterator iter = derived.begin(); iter != derived.end(); iter++)
|
|
|
{
|
|
|
- global << " hierarchy[\"" << baseClasses[i] << "\"].push_back(\"" << *iter << "\");\n";
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(*iter) == _namespaces["gameplay"].end()))
|
|
|
+ global << " ScriptUtil::setGlobalHierarchyPair(\"" << baseClasses[i] << "\", \"" << *iter << "\");\n";
|
|
|
}
|
|
|
}
|
|
|
- global << " ScriptUtil::setGlobalHierarchy(hierarchy);\n";
|
|
|
}
|
|
|
|
|
|
// Register all enums.
|
|
|
- if (_enums.size() > 0)
|
|
|
+ if (generateEnumBindings)
|
|
|
{
|
|
|
+ global << " ScriptUtil::addStringFromEnumConversionFunction(&";
|
|
|
+ if (bindingNS)
|
|
|
+ global << *bindingNS << "::";
|
|
|
+ global << "lua_stringFromEnumGlobal);\n";
|
|
|
+
|
|
|
for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
{
|
|
|
- global << "\n // Register enumeration " << iter->first << ".\n";
|
|
|
- global << " {\n";
|
|
|
-
|
|
|
- global << " std::vector<std::string> scopePath;\n";
|
|
|
- for (unsigned int i = 0; i < iter->second.scopePath.size(); i++)
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->first) == _namespaces["gameplay"].end()))
|
|
|
{
|
|
|
- global << " scopePath.push_back(\"" << iter->second.scopePath[i] << "\");\n";
|
|
|
- }
|
|
|
+ global << "\n // Register enumeration " << iter->first << ".\n";
|
|
|
+ global << " {\n";
|
|
|
|
|
|
- vector<string>::iterator enumIter = iter->second.values.begin();
|
|
|
- for (; enumIter != iter->second.values.end(); enumIter++)
|
|
|
- {
|
|
|
- global << " ScriptUtil::registerConstantString(\"" << *enumIter << "\", \"" << *enumIter << "\", scopePath);\n";
|
|
|
- }
|
|
|
+ global << " std::vector<std::string> scopePath;\n";
|
|
|
+ for (unsigned int i = 0; i < iter->second.scopePath.size(); i++)
|
|
|
+ {
|
|
|
+ global << " scopePath.push_back(\"" << iter->second.scopePath[i] << "\");\n";
|
|
|
+ }
|
|
|
|
|
|
- global << " }\n";
|
|
|
+ vector<string>::iterator enumIter = iter->second.values.begin();
|
|
|
+ for (; enumIter != iter->second.values.end(); enumIter++)
|
|
|
+ {
|
|
|
+ global << " ScriptUtil::registerConstantString(\"" << *enumIter << "\", \"" << *enumIter << "\", scopePath);\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ global << " }\n";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
global << "}\n\n";
|
|
|
|
|
|
// Write out the binding functions.
|
|
|
- for (map<string, vector<FunctionBinding> >::iterator iter = _functions.begin(); iter != _functions.end(); iter++)
|
|
|
+ if (generateGlobalFunctionBindings)
|
|
|
{
|
|
|
- FunctionBinding::write(global, iter->second);
|
|
|
+ for (map<string, vector<FunctionBinding> >::iterator iter = _functions.begin(); iter != _functions.end(); iter++)
|
|
|
+ {
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->second[0].name) == _namespaces["gameplay"].end()))
|
|
|
+ FunctionBinding::write(global, iter->second);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Write out the global enum conversion function (used to pass enums from C++ to Lua).
|
|
|
- global << "static const char* enumStringEmpty = \"\";\n\n";
|
|
|
- global << "const char* lua_stringFromEnumGlobal(std::string& enumname, unsigned int value)\n";
|
|
|
- global << "{\n";
|
|
|
- for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
+ if (generateEnumBindings)
|
|
|
{
|
|
|
- global << " if (enumname == \"";
|
|
|
- global << iter->first << "\")\n";
|
|
|
- global << " return lua_stringFromEnum_" << getUniqueName(iter->first) << "((" << iter->first << ")value);\n";
|
|
|
+ global << "static const char* enumStringEmpty = \"\";\n\n";
|
|
|
+ global << "const char* lua_stringFromEnumGlobal(std::string& enumname, unsigned int value)\n";
|
|
|
+ global << "{\n";
|
|
|
+ for (map<string, EnumBinding>::iterator iter = _enums.begin(); iter != _enums.end(); iter++)
|
|
|
+ {
|
|
|
+ if (generatingGameplay || (!generatingGameplay && _namespaces["gameplay"].find(iter->first) == _namespaces["gameplay"].end()))
|
|
|
+ {
|
|
|
+ global << " if (enumname == \"";
|
|
|
+ global << iter->first << "\")\n";
|
|
|
+ global << " return lua_stringFromEnum_" << getUniqueName(iter->first) << "((" << iter->first << ")value);\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ global << "\n";
|
|
|
+ global << " GP_ERROR(\"Unrecognized enumeration type '%s'.\", enumname.c_str());\n";
|
|
|
+ global << " return enumStringEmpty;\n";
|
|
|
+ global << "}\n\n";
|
|
|
}
|
|
|
- global << "\n";
|
|
|
- global << " GP_ERROR(\"Unrecognized enumeration type '%s'.\", enumname.c_str());\n";
|
|
|
- global << " return enumStringEmpty;\n";
|
|
|
- global << "}\n\n";
|
|
|
|
|
|
if (bindingNS)
|
|
|
global << "}\n";
|
|
|
@@ -1677,8 +1761,6 @@ void Generator::generateBindings()
|
|
|
luaAllH<< "}\n\n";
|
|
|
luaAllH << "#endif\n";
|
|
|
luaAllH.close();
|
|
|
-
|
|
|
- SAFE_DELETE(bindingNS);
|
|
|
}
|
|
|
|
|
|
void Generator::getAllDerived(set<string>& derived, string classname)
|