mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r23351) -Add: generate the correct API type when creating Squirrel glue (Rubidium)
This commit is contained in:
parent
bff7c33aa9
commit
96249564fd
@ -7,7 +7,7 @@
|
||||
|
||||
#
|
||||
# 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...
|
||||
#
|
||||
@ -168,6 +168,11 @@ BEGIN {
|
||||
public = "false"
|
||||
namespace_opened = "false"
|
||||
|
||||
api_cls = cls
|
||||
gsub("^Script", api, api_cls)
|
||||
api_super_cls = super_cls
|
||||
gsub("^Script", api, api_super_cls)
|
||||
|
||||
print ""
|
||||
|
||||
# First check whether we have enums to print
|
||||
@ -209,20 +214,20 @@ BEGIN {
|
||||
print "} // namespace SQConvert"
|
||||
|
||||
print "";
|
||||
print "template <> const char *GetClassName<" cls ", ST_AI>() { return \"" cls "\"; }"
|
||||
print "template <> const char *GetClassName<" cls ", ST_" toupper(api) ">() { return \"" api_cls "\"; }"
|
||||
print "";
|
||||
|
||||
# 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 " 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") {
|
||||
print " SQ" cls ".PreRegister(engine);"
|
||||
print " SQ" api_cls ".PreRegister(engine);"
|
||||
} else {
|
||||
print " SQ" cls ".PreRegister(engine, \"" super_cls "\");"
|
||||
print " SQ" api_cls ".PreRegister(engine, \"" api_super_cls "\");"
|
||||
}
|
||||
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 ""
|
||||
|
||||
@ -232,7 +237,7 @@ BEGIN {
|
||||
if (mlen <= length(enum_value[i])) mlen = length(enum_value[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]
|
||||
}
|
||||
if (enum_value_size != 0) print ""
|
||||
@ -243,7 +248,7 @@ BEGIN {
|
||||
if (mlen <= length(const_value[i])) mlen = length(const_value[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]
|
||||
}
|
||||
if (const_size != 0) print ""
|
||||
@ -277,7 +282,7 @@ BEGIN {
|
||||
if (mlen <= length(static_methods[i, 0])) mlen = length(static_methods[i, 0])
|
||||
}
|
||||
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]
|
||||
}
|
||||
if (static_method_size != 0) print ""
|
||||
@ -290,15 +295,15 @@ BEGIN {
|
||||
}
|
||||
for (i = 1; i <= method_size; i++) {
|
||||
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 {
|
||||
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]
|
||||
}
|
||||
if (method_size != 0) print ""
|
||||
}
|
||||
print " SQ" cls ".PostRegister(engine);"
|
||||
print " SQ" api_cls ".PostRegister(engine);"
|
||||
print "}"
|
||||
|
||||
enum_size = 0
|
||||
|
@ -20,7 +20,9 @@ if [ "$?" != "0" ]; then
|
||||
exit 1
|
||||
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
|
||||
for f in `ls *.hpp`; do
|
||||
@ -28,7 +30,7 @@ if [ -z "$1" ]; then
|
||||
# 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;
|
||||
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
|
||||
mv ${f}.tmp ${f}.sq
|
||||
echo "Updated: ${f}.sq"
|
||||
@ -40,7 +42,7 @@ if [ -z "$1" ]; then
|
||||
fi
|
||||
done
|
||||
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
|
||||
mv $1.tmp $1.sq
|
||||
echo "Updated: $1.sq"
|
||||
@ -61,8 +63,8 @@ for f in `ls *.hpp.sq`; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Add stuff to ai_instance.cpp
|
||||
f='../ai_instance.cpp'
|
||||
# Add stuff to ${apilc}_instance.cpp
|
||||
f="../${apilc}_instance.cpp"
|
||||
|
||||
functions=``
|
||||
|
||||
@ -70,13 +72,13 @@ echo "
|
||||
{ }
|
||||
/.hpp.sq/ { next }
|
||||
/squirrel_register_std/ { next }
|
||||
/SQAIController_Register/ { print \$0; next }
|
||||
/SQAI.*_Register/ { next }
|
||||
/SQ${apiuc}Controller_Register/ { print \$0; next }
|
||||
/SQ${apiuc}.*_Register/ { next }
|
||||
|
||||
/Note: this line is a marker in squirrel_export.sh. Do not change!/ {
|
||||
print \$0
|
||||
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++) {
|
||||
print \"#include \\\"api/\" files[i] \"\\\"\" \$0
|
||||
@ -89,12 +91,12 @@ echo "
|
||||
print \$0
|
||||
gsub(\"^.*/\", \"\")
|
||||
print \" squirrel_register_std(this->engine);\" \$0
|
||||
# AIList needs to be registered with squirrel before all AIList subclasses.
|
||||
print \" SQAIList_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, \" \")
|
||||
# List needs to be registered with squirrel before all List subclasses.
|
||||
print \" SQ${apiuc}List_Register(this->engine);\" \$0
|
||||
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++) {
|
||||
if (regs[i] == \"SQAIController_Register(this->engine);\") continue
|
||||
if (regs[i] == \"SQ${apiuc}Controller_Register(this->engine);\") continue
|
||||
print \" \" regs[i] \$0
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user