(svn r23351) -Add: generate the correct API type when creating Squirrel glue (Rubidium)

This commit is contained in:
truebrain 2011-11-29 22:24:04 +00:00
parent d413dcabbf
commit cb76833b6c
2 changed files with 32 additions and 25 deletions

View File

@ -7,7 +7,7 @@
# #
# Awk script to automatically generate the code needed # Awk script to automatically generate the code needed
# to export the AI API to Squirrel. # to export the script APIs to Squirrel.
# #
# Note that arrays are 1 based... # Note that arrays are 1 based...
# #
@ -168,6 +168,11 @@ BEGIN {
public = "false" public = "false"
namespace_opened = "false" namespace_opened = "false"
api_cls = cls
gsub("^Script", api, api_cls)
api_super_cls = super_cls
gsub("^Script", api, api_super_cls)
print "" print ""
# First check whether we have enums to print # First check whether we have enums to print
@ -209,20 +214,20 @@ BEGIN {
print "} // namespace SQConvert" print "} // namespace SQConvert"
print ""; print "";
print "template <> const char *GetClassName<" cls ", ST_AI>() { return \"" cls "\"; }" print "template <> const char *GetClassName<" cls ", ST_" toupper(api) ">() { return \"" api_cls "\"; }"
print ""; print "";
# Then do the registration functions of the class. */ # Then do the registration functions of the class. */
print "void SQ" cls "_Register(Squirrel *engine)" print "void SQ" api_cls "_Register(Squirrel *engine)"
print "{" print "{"
print " DefSQClass<" cls ", ST_AI> SQ" cls "(\"" cls "\");" print " DefSQClass<" cls ", ST_" toupper(api) "> SQ" api_cls "(\"" api_cls "\");"
if (super_cls == "AIObject" || super_cls == "AIAbstractList::Valuator") { if (super_cls == "AIObject" || super_cls == "AIAbstractList::Valuator") {
print " SQ" cls ".PreRegister(engine);" print " SQ" api_cls ".PreRegister(engine);"
} else { } else {
print " SQ" cls ".PreRegister(engine, \"" super_cls "\");" print " SQ" api_cls ".PreRegister(engine, \"" api_super_cls "\");"
} }
if (virtual_class == "false" && super_cls != "AIEvent") { if (virtual_class == "false" && super_cls != "AIEvent") {
print " SQ" cls ".AddConstructor<void (" cls "::*)(" cls_param[0] "), " cls_param[1]">(engine, \"" cls_param[2] "\");" print " SQ" api_cls ".AddConstructor<void (" cls "::*)(" cls_param[0] "), " cls_param[1]">(engine, \"" cls_param[2] "\");"
} }
print "" print ""
@ -232,7 +237,7 @@ BEGIN {
if (mlen <= length(enum_value[i])) mlen = length(enum_value[i]) if (mlen <= length(enum_value[i])) mlen = length(enum_value[i])
} }
for (i = 1; i <= enum_value_size; i++) { for (i = 1; i <= enum_value_size; i++) {
print " SQ" cls ".DefSQConst(engine, " cls "::" enum_value[i] ", " substr(spaces, 1, mlen - length(enum_value[i])) "\"" enum_value[i] "\");" print " SQ" api_cls ".DefSQConst(engine, " cls "::" enum_value[i] ", " substr(spaces, 1, mlen - length(enum_value[i])) "\"" enum_value[i] "\");"
delete enum_value[i] delete enum_value[i]
} }
if (enum_value_size != 0) print "" if (enum_value_size != 0) print ""
@ -243,7 +248,7 @@ BEGIN {
if (mlen <= length(const_value[i])) mlen = length(const_value[i]) if (mlen <= length(const_value[i])) mlen = length(const_value[i])
} }
for (i = 1; i <= const_size; i++) { for (i = 1; i <= const_size; i++) {
print " SQ" cls ".DefSQConst(engine, " cls "::" const_value[i] ", " substr(spaces, 1, mlen - length(const_value[i])) "\"" const_value[i] "\");" print " SQ" api_cls ".DefSQConst(engine, " cls "::" const_value[i] ", " substr(spaces, 1, mlen - length(const_value[i])) "\"" const_value[i] "\");"
delete const_value[i] delete const_value[i]
} }
if (const_size != 0) print "" if (const_size != 0) print ""
@ -277,7 +282,7 @@ BEGIN {
if (mlen <= length(static_methods[i, 0])) mlen = length(static_methods[i, 0]) if (mlen <= length(static_methods[i, 0])) mlen = length(static_methods[i, 0])
} }
for (i = 1; i <= static_method_size; i++) { for (i = 1; i <= static_method_size; i++) {
print " SQ" cls ".DefSQStaticMethod(engine, &" cls "::" static_methods[i, 0] ", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "\"" static_methods[i, 0] "\", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "" static_methods[i, 1] ", \"" static_methods[i, 2] "\");" print " SQ" api_cls ".DefSQStaticMethod(engine, &" cls "::" static_methods[i, 0] ", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "\"" static_methods[i, 0] "\", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "" static_methods[i, 1] ", \"" static_methods[i, 2] "\");"
delete static_methods[i] delete static_methods[i]
} }
if (static_method_size != 0) print "" if (static_method_size != 0) print ""
@ -290,15 +295,15 @@ BEGIN {
} }
for (i = 1; i <= method_size; i++) { for (i = 1; i <= method_size; i++) {
if (methods[i, 2] == "v") { if (methods[i, 2] == "v") {
print " SQ" cls ".DefSQAdvancedMethod(engine, &" cls "::" methods[i, 0] ", " substr(spaces, 1, mlen - length(methods[i, 0]) - 8) "\"" methods[i, 0] "\");" print " SQ" api_cls ".DefSQAdvancedMethod(engine, &" cls "::" methods[i, 0] ", " substr(spaces, 1, mlen - length(methods[i, 0]) - 8) "\"" methods[i, 0] "\");"
} else { } else {
print " SQ" cls ".DefSQMethod(engine, &" cls "::" methods[i, 0] ", " substr(spaces, 1, mlen - length(methods[i, 0])) "\"" methods[i, 0] "\", " substr(spaces, 1, mlen - length(methods[i, 0])) "" methods[i, 1] ", \"" methods[i, 2] "\");" print " SQ" api_cls ".DefSQMethod(engine, &" cls "::" methods[i, 0] ", " substr(spaces, 1, mlen - length(methods[i, 0])) "\"" methods[i, 0] "\", " substr(spaces, 1, mlen - length(methods[i, 0])) "" methods[i, 1] ", \"" methods[i, 2] "\");"
} }
delete methods[i] delete methods[i]
} }
if (method_size != 0) print "" if (method_size != 0) print ""
} }
print " SQ" cls ".PostRegister(engine);" print " SQ" api_cls ".PostRegister(engine);"
print "}" print "}"
enum_size = 0 enum_size = 0

View File

@ -20,7 +20,9 @@ if [ "$?" != "0" ]; then
exit 1 exit 1
fi fi
# This must be called from within the src/ai/api directory. # This must be called from within a src/???/api directory.
apilc=`pwd | sed "s@/api@@;s@.*/@@"`
apiuc=`echo ${apilc} | tr [a-z] [A-Z]`
if [ -z "$1" ]; then if [ -z "$1" ]; then
for f in `ls *.hpp`; do for f in `ls *.hpp`; do
@ -28,7 +30,7 @@ if [ -z "$1" ]; then
# these files should not be changed by this script # these files should not be changed by this script
"ai_controller.hpp" | "ai_object.hpp" | "ai_types.hpp" | "ai_changelog.hpp" | "ai_info_docs.hpp" ) continue; "ai_controller.hpp" | "ai_object.hpp" | "ai_types.hpp" | "ai_changelog.hpp" | "ai_info_docs.hpp" ) continue;
esac esac
${AWK} -f squirrel_export.awk ${f} > ${f}.tmp ${AWK} -v api=${apiuc} -f squirrel_export.awk ${f} > ${f}.tmp
if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' ${f}.tmp ${f}.sq 2> /dev/null || echo boo`" ]; then if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' ${f}.tmp ${f}.sq 2> /dev/null || echo boo`" ]; then
mv ${f}.tmp ${f}.sq mv ${f}.tmp ${f}.sq
echo "Updated: ${f}.sq" echo "Updated: ${f}.sq"
@ -40,7 +42,7 @@ if [ -z "$1" ]; then
fi fi
done done
else else
${AWK} -f squirrel_export.awk $1 > $1.tmp ${AWK} -v api=${apiuc} -f squirrel_export.awk $1 > $1.tmp
if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' $1.sq $1.tmp 2> /dev/null || echo boo`" ]; then if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' $1.sq $1.tmp 2> /dev/null || echo boo`" ]; then
mv $1.tmp $1.sq mv $1.tmp $1.sq
echo "Updated: $1.sq" echo "Updated: $1.sq"
@ -61,8 +63,8 @@ for f in `ls *.hpp.sq`; do
fi fi
done done
# Add stuff to ai_instance.cpp # Add stuff to ${apilc}_instance.cpp
f='../ai_instance.cpp' f="../${apilc}_instance.cpp"
functions=`` functions=``
@ -70,13 +72,13 @@ echo "
{ } { }
/.hpp.sq/ { next } /.hpp.sq/ { next }
/squirrel_register_std/ { next } /squirrel_register_std/ { next }
/SQAIController_Register/ { print \$0; next } /SQ${apiuc}Controller_Register/ { print \$0; next }
/SQAI.*_Register/ { next } /SQ${apiuc}.*_Register/ { next }
/Note: this line is a marker in squirrel_export.sh. Do not change!/ { /Note: this line is a marker in squirrel_export.sh. Do not change!/ {
print \$0 print \$0
gsub(\"^.*/\", \"\") gsub(\"^.*/\", \"\")
split(\"`grep '^void SQAI.*_Register(Squirrel \*engine)$' *.hpp.sq | sed 's/:.*$//' | sort | uniq | tr -d '\r' | tr '\n' ' '`\", files, \" \") split(\"`grep '^void SQ'${apiuc}'.*_Register(Squirrel \*engine)$' *.hpp.sq | sed 's/:.*$//' | sort | uniq | tr -d '\r' | tr '\n' ' '`\", files, \" \")
for (i = 1; files[i] != \"\"; i++) { for (i = 1; files[i] != \"\"; i++) {
print \"#include \\\"api/\" files[i] \"\\\"\" \$0 print \"#include \\\"api/\" files[i] \"\\\"\" \$0
@ -89,12 +91,12 @@ echo "
print \$0 print \$0
gsub(\"^.*/\", \"\") gsub(\"^.*/\", \"\")
print \" squirrel_register_std(this->engine);\" \$0 print \" squirrel_register_std(this->engine);\" \$0
# AIList needs to be registered with squirrel before all AIList subclasses. # List needs to be registered with squirrel before all List subclasses.
print \" SQAIList_Register(this->engine);\" \$0 print \" SQ${apiuc}List_Register(this->engine);\" \$0
split(\"`grep '^void SQAI.*_Register(Squirrel \*engine)$' *.hpp.sq | grep -v 'SQAIList_Register' | sed 's/^.*void //;s/Squirrel \*/this->/;s/$/;/;s/_Register/0000Register/g;' | sort | sed 's/0000Register/_Register/g' | tr -d '\r' | tr '\n' ' '`\", regs, \" \") split(\"`grep '^void SQ'${apiuc}'.*_Register(Squirrel \*engine)$' *.hpp.sq | grep -v 'SQ'${apiuc}'List_Register' | sed 's/^.*void //;s/Squirrel \*/this->/;s/$/;/;s/_Register/0000Register/g;' | sort | sed 's/0000Register/_Register/g' | tr -d '\r' | tr '\n' ' '`\", regs, \" \")
for (i = 1; regs[i] != \"\"; i++) { for (i = 1; regs[i] != \"\"; i++) {
if (regs[i] == \"SQAIController_Register(this->engine);\") continue if (regs[i] == \"SQ${apiuc}Controller_Register(this->engine);\") continue
print \" \" regs[i] \$0 print \" \" regs[i] \$0
} }