summaryrefslogtreecommitdiff
path: root/src/script/api/squirrel_export.awk
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-11-29 23:29:20 +0000
committertruebrain <truebrain@openttd.org>2011-11-29 23:29:20 +0000
commit7158aaea3100fbae72c75645800592117375f897 (patch)
tree30b4f0058553c0246ea3c5d773972bbafedac5b7 /src/script/api/squirrel_export.awk
parente60747a6043d42b872d02ba667f99187b5d3f1d7 (diff)
downloadopenttd-7158aaea3100fbae72c75645800592117375f897.tar.xz
(svn r23373) -Add: move the AI API to script/api/ai, and move the Squirrel C++ glue templates to script/api/template
Diffstat (limited to 'src/script/api/squirrel_export.awk')
-rw-r--r--src/script/api/squirrel_export.awk74
1 files changed, 45 insertions, 29 deletions
diff --git a/src/script/api/squirrel_export.awk b/src/script/api/squirrel_export.awk
index 56d5ee1b3..781c452d5 100644
--- a/src/script/api/squirrel_export.awk
+++ b/src/script/api/squirrel_export.awk
@@ -54,7 +54,11 @@ function dump_fileheader()
print ""
print "/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */"
print ""
- print "#include \"../../script/api/" filename "\""
+ print "#include \"../" filename "\""
+ if (api != "Template") {
+ gsub("script_", "template_", filename)
+ print "#include \"../template/" filename ".sq\""
+ }
}
function reset_reader()
@@ -99,6 +103,11 @@ BEGIN {
}
/^([ ]*)\* @api/ {
+ if (api == "Template") {
+ api_selected = "true"
+ next
+ }
+
# By default, classes are not selected
if (cls_level == 0) api_selected = "false"
@@ -114,6 +123,8 @@ BEGIN {
} else if (match($0, tolower(api))) {
api_selected = "true"
}
+
+ next
}
# Remove the old squirrel stuff
@@ -259,43 +270,48 @@ BEGIN {
print ""
- # First check whether we have enums to print
- if (enum_size != 0) {
- if (namespace_opened == "false") {
- print "namespace SQConvert {"
- namespace_opened = "true"
+ if (api == "Template") {
+ # First check whether we have enums to print
+ if (enum_size != 0) {
+ if (namespace_opened == "false") {
+ print "namespace SQConvert {"
+ namespace_opened = "true"
+ }
+ print " /* Allow enums to be used as Squirrel parameters */"
+ for (i = 1; i <= enum_size; i++) {
+ print " template <> inline " enums[i] " GetParam(ForceType<" enums[i] ">, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (" enums[i] ")tmp; }"
+ print " template <> inline int Return<" enums[i] ">(HSQUIRRELVM vm, " enums[i] " res) { sq_pushinteger(vm, (int32)res); return 1; }"
+ delete enums[i]
+ }
}
- print " /* Allow enums to be used as Squirrel parameters */"
- for (i = 1; i <= enum_size; i++) {
- print " template <> inline " enums[i] " GetParam(ForceType<" enums[i] ">, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (" enums[i] ")tmp; }"
- print " template <> inline int Return<" enums[i] ">(HSQUIRRELVM vm, " enums[i] " res) { sq_pushinteger(vm, (int32)res); return 1; }"
- delete enums[i]
+
+ # Then check whether we have structs/classes to print
+ if (struct_size != 0) {
+ if (namespace_opened == "false") {
+ print "namespace SQConvert {"
+ namespace_opened = "true"
+ }
+ print " /* Allow inner classes/structs to be used as Squirrel parameters */"
+ for (i = 1; i <= struct_size; i++) {
+ dump_class_templates(structs[i])
+ delete structs[i]
+ }
}
- }
- # Then check whether we have structs/classes to print
- if (struct_size != 0) {
if (namespace_opened == "false") {
print "namespace SQConvert {"
namespace_opened = "true"
+ } else {
+ print ""
}
- print " /* Allow inner classes/structs to be used as Squirrel parameters */"
- for (i = 1; i <= struct_size; i++) {
- dump_class_templates(structs[i])
- delete structs[i]
- }
- }
+ print " /* Allow " cls " to be used as Squirrel parameter */"
+ dump_class_templates(cls)
- if (namespace_opened == "false") {
- print "namespace SQConvert {"
- namespace_opened = "true"
- } else {
- print ""
- }
- print " /* Allow " cls " to be used as Squirrel parameter */"
- dump_class_templates(cls)
+ print "} // namespace SQConvert"
- print "} // namespace SQConvert"
+ reset_reader()
+ next
+ }
print "";
print "template <> const char *GetClassName<" cls ", ST_" toupper(api) ">() { return \"" api_cls "\"; }"