2019-03-12 14:37:57 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT SCRIPT_API_SOURCE_FILE)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs SCRIPT_API_SOURCE_FILE defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT SCRIPT_API_BINARY_FILE)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs SCRIPT_API_BINARY_FILE defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT SCRIPT_API_FILE)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs SCRIPT_API_FILE defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT APIUC)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs APIUC defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT APILC)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs APILC defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
macro(dump_fileheader)
|
|
|
|
get_filename_component(SCRIPT_API_FILE_NAME "${SCRIPT_API_FILE}" NAME)
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n#include \"../${SCRIPT_API_FILE_NAME}\"")
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT "${APIUC}" STREQUAL "Template")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(REPLACE "script_" "template_" SCRIPT_API_FILE_NAME "${SCRIPT_API_FILE_NAME}")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n#include \"../template/${SCRIPT_API_FILE_NAME}.sq\"")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
macro(dump_class_templates NAME)
|
|
|
|
string(REGEX REPLACE "^Script" "" REALNAME ${NAME})
|
|
|
|
|
2023-05-06 08:24:31 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<${NAME} *> { static inline ${NAME} *Get(HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return (${NAME} *)instance; } };")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<${NAME} &> { static inline ${NAME} &Get(HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return *(${NAME} *)instance; } };")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<const ${NAME} *> { static inline const ${NAME} *Get(HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return (${NAME} *)instance; } };")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<const ${NAME} &> { static inline const ${NAME} &Get(HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, nullptr); return *(${NAME} *)instance; } };")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${NAME}" STREQUAL "ScriptEvent")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Return<${NAME} *> { static inline int Set(HSQUIRRELVM vm, ${NAME} *res) { if (res == nullptr) { sq_pushnull(vm); return 1; } Squirrel::CreateClassInstanceVM(vm, \"${REALNAME}\", res, nullptr, DefSQDestructorCallback<${NAME}>, true); return 1; } };")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${NAME}" STREQUAL "ScriptText")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<Text *> {")
|
2023-05-06 08:24:31 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n static inline Text *Get(HSQUIRRELVM vm, int index) {")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n if (sq_gettype(vm, index) == OT_INSTANCE) {")
|
2023-05-06 08:24:31 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n return Param<ScriptText *>::Get(vm, index);")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n }")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n if (sq_gettype(vm, index) == OT_STRING) {")
|
2023-05-06 08:24:31 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n return new RawText(Param<const std::string &>::Get(vm, index));")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n }")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n return nullptr;")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n }")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n };")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Return<${NAME} *> { static inline int Set(HSQUIRRELVM vm, ${NAME} *res) { if (res == nullptr) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, \"${REALNAME}\", res, nullptr, DefSQDestructorCallback<${NAME}>, true); return 1; } };")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
macro(reset_reader)
|
|
|
|
unset(ENUMS)
|
|
|
|
unset(ENUM_VALUES)
|
|
|
|
unset(CONST_VALUES)
|
|
|
|
unset(STRUCTS)
|
|
|
|
unset(ENUM_STRING_TO_ERRORS)
|
|
|
|
unset(ENUM_ERROR_TO_STRINGS)
|
|
|
|
unset(METHODS)
|
|
|
|
unset(STATIC_METHODS)
|
|
|
|
unset(CLS)
|
|
|
|
unset(START_SQUIRREL_DEFINE_ON_NEXT_LINE)
|
|
|
|
set(CLS_LEVEL 0)
|
|
|
|
unset(CLS_IN_API)
|
2020-09-25 11:55:25 +00:00
|
|
|
endmacro()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
reset_reader()
|
|
|
|
|
|
|
|
file(STRINGS "${SCRIPT_API_FILE}" SOURCE_LINES)
|
|
|
|
|
2024-01-05 16:52:13 +00:00
|
|
|
set(NUM_LINE 0)
|
|
|
|
macro(doxygen_check)
|
|
|
|
if(NOT "${DOXYGEN_SKIP}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "${SCRIPT_API_FILE}:${NUM_LINE}: a DOXYGEN_API block was not properly closed")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(LINE IN LISTS SOURCE_LINES)
|
2024-01-05 16:52:13 +00:00
|
|
|
math(EXPR NUM_LINE "${NUM_LINE} + 1")
|
2019-03-12 14:37:57 +00:00
|
|
|
# Ignore special doxygen blocks
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^#ifndef DOXYGEN_API")
|
2024-01-05 16:52:13 +00:00
|
|
|
doxygen_check()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(DOXYGEN_SKIP "next")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^#ifdef DOXYGEN_API")
|
2024-01-05 16:52:13 +00:00
|
|
|
doxygen_check()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(DOXYGEN_SKIP "true")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^#endif /\\* DOXYGEN_API \\*/")
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(DOXYGEN_SKIP)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^#else")
|
2024-01-05 16:52:13 +00:00
|
|
|
if(DOXYGEN_SKIP STREQUAL "next")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(DOXYGEN_SKIP "true")
|
2024-01-05 16:52:13 +00:00
|
|
|
elseif(DOXYGEN_SKIP STREQUAL "true")
|
|
|
|
set(DOXYGEN_SKIP "false")
|
2019-03-12 14:37:57 +00:00
|
|
|
endif()
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${DOXYGEN_SKIP}" STREQUAL "true")
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^([ ]*)\\* @api (.*)$")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(LINE ${CMAKE_MATCH_2})
|
|
|
|
# By default, classes are not selected
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT CLS_LEVEL)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED FALSE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${APIUC}" STREQUAL "Template")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" STREQUAL "none" OR "${LINE}" STREQUAL "-all")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED FALSE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" STREQUAL "none" OR "${LINE}" STREQUAL "-all")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED FALSE)
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${LINE}" MATCHES "-${APILC}")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED FALSE)
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${LINE}" MATCHES "${APILC}")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Remove the old squirrel stuff
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "#ifdef DEFINE_SQUIRREL_CLASS")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(SQUIRREL_STUFF TRUE)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^#endif /\\* DEFINE_SQUIRREL_CLASS \\*/")
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(SQUIRREL_STUFF)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(SQUIRREL_STUFF)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Ignore forward declarations of classes
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^( *)class(.*);")
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# We only want to have public functions exported for now
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^( *)class (.*) (: public|: protected|: private|:) ([^ ]*)")
|
|
|
|
if(NOT CLS_LEVEL)
|
|
|
|
if(NOT DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(WARNING "Class '${CMAKE_MATCH_2}' has no @api. It won't be published to any API.")
|
|
|
|
set(API_SELECTED FALSE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(IS_PUBLIC)
|
|
|
|
unset(CLS_PARAM_0)
|
|
|
|
set(CLS_PARAM_1 1)
|
|
|
|
set(CLS_PARAM_2 "x")
|
|
|
|
set(CLS_IN_API ${API_SELECTED})
|
|
|
|
unset(API_SELECTED)
|
|
|
|
set(CLS "${CMAKE_MATCH_2}")
|
|
|
|
set(SUPER_CLS "${CMAKE_MATCH_4}")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif(CLS_LEVEL EQUAL 1)
|
|
|
|
if(NOT DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED ${CLS_IN_API})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
list(APPEND STRUCTS "${CLS}::${CMAKE_MATCH_2}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^( *)public")
|
|
|
|
if(CLS_LEVEL EQUAL 1)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(IS_PUBLIC TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^( *)protected")
|
|
|
|
if(CLS_LEVEL EQUAL 1)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(IS_PUBLIC)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "^( *)private")
|
|
|
|
if(CLS_LEVEL EQUAL 1)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(IS_PUBLIC)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Ignore the comments
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^#")
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "/\\*.*\\*/")
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(COMMENT)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "/\\*")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(COMMENT TRUE)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "\\*/")
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(COMMENT)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(COMMENT)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# We need to make specialized conversions for structs
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^( *)struct ([^ ]*)")
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
|
|
|
|
|
|
|
# Check if we want to publish this struct
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED ${CLS_IN_API})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT IS_PUBLIC OR NOT CLS_LEVEL EQUAL 1)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
list(APPEND STRUCTS "${CLS}::${CMAKE_MATCH_2}")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# We need to make specialized conversions for enums
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^( *)enum ([^ ]*)")
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
|
|
|
|
|
|
|
# Check if we want to publish this enum
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED ${CLS_IN_API})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT IS_PUBLIC)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
set(IN_ENUM TRUE)
|
|
|
|
list(APPEND ENUMS "${CLS}::${CMAKE_MATCH_2}")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Maybe the end of the class, if so we can start with the Squirrel export pretty soon
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "};")
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR CLS_LEVEL "${CLS_LEVEL} - 1")
|
2020-09-25 11:55:25 +00:00
|
|
|
if(CLS_LEVEL)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(IN_ENUM)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(CLS)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(START_SQUIRREL_DEFINE_ON_NEXT_LINE TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Empty/white lines. When we may do the Squirrel export, do that export.
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^([ ]*)$")
|
|
|
|
if(NOT START_SQUIRREL_DEFINE_ON_NEXT_LINE)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT CLS_IN_API)
|
2019-03-12 14:37:57 +00:00
|
|
|
reset_reader()
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT HAS_FILEHEADER)
|
2019-03-12 14:37:57 +00:00
|
|
|
dump_fileheader()
|
|
|
|
set(HAS_FILEHEADER TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
unset(IS_PUBLIC)
|
|
|
|
unset(NAMESPACE_OPENED)
|
|
|
|
|
|
|
|
string(REGEX REPLACE "^Script" "${APIUC}" API_CLS "${CLS}")
|
|
|
|
string(REGEX REPLACE "^Script" "${APIUC}" API_SUPER_CLS "${SUPER_CLS}")
|
|
|
|
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${APIUC}" STREQUAL "Template")
|
2019-03-12 14:37:57 +00:00
|
|
|
# First check whether we have enums to print
|
2020-09-25 11:55:25 +00:00
|
|
|
if(DEFINED ENUMS)
|
|
|
|
if(NOT NAMESPACE_OPENED)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
|
|
|
set(NAMESPACE_OPENED TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n /* Allow enums to be used as Squirrel parameters */")
|
|
|
|
foreach(ENUM IN LISTS ENUMS)
|
2023-05-06 08:24:31 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<${ENUM}> { static inline ${ENUM} Get(HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (${ENUM})tmp; } };")
|
2022-01-16 23:54:59 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n template <> struct Return<${ENUM}> { static inline int Set(HSQUIRRELVM vm, ${ENUM} res) { sq_pushinteger(vm, res); return 1; } };")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Then check whether we have structs/classes to print
|
2020-09-25 11:55:25 +00:00
|
|
|
if(DEFINED STRUCTS)
|
|
|
|
if(NOT NAMESPACE_OPENED)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
|
|
|
set(NAMESPACE_OPENED TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n /* Allow inner classes/structs to be used as Squirrel parameters */")
|
|
|
|
foreach(STRUCT IN LISTS STRUCTS)
|
|
|
|
dump_class_templates(${STRUCT})
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT NAMESPACE_OPENED)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
|
|
|
set(NAMESPACE_OPENED TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n /* Allow ${CLS} to be used as Squirrel parameter */")
|
|
|
|
dump_class_templates(${CLS})
|
|
|
|
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n} // namespace SQConvert")
|
|
|
|
|
|
|
|
reset_reader()
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2023-04-16 19:00:55 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\ntemplate <> const char *GetClassName<${CLS}, ScriptType::${APIUC}>() { return \"${API_CLS}\"; }")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
|
|
|
|
|
|
|
# Then do the registration functions of the class.
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\nvoid SQ${API_CLS}_Register(Squirrel *engine)")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n{")
|
2023-04-16 19:00:55 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${SUPER_CLS}" STREQUAL "Text" OR "${SUPER_CLS}" STREQUAL "ScriptObject" OR "${SUPER_CLS}" STREQUAL "AIAbstractiveList::Valuator")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine);")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine, \"${API_SUPER_CLS}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2023-01-25 20:41:58 +00:00
|
|
|
if(NOT "${SUPER_CLS}" MATCHES "^ScriptEvent")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${CLS_PARAM_2}" STREQUAL "v")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.AddSQAdvancedConstructor(engine);")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.AddConstructor<void (${CLS}::*)(${CLS_PARAM_0}), ${CLS_PARAM_1}>(engine, \"${CLS_PARAM_2}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
|
|
|
|
|
|
|
# Enum values
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(ENUM_VALUE IN LISTS ENUM_VALUES)
|
|
|
|
string(LENGTH "${ENUM_VALUE}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(ENUM_VALUE IN LISTS ENUM_VALUES)
|
|
|
|
string(LENGTH "${ENUM_VALUE}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQConst(engine, ${CLS}::${ENUM_VALUE},${SPACES}\"${ENUM_VALUE}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Const values
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(CONST_VALUE IN LISTS CONST_VALUES)
|
|
|
|
string(LENGTH "${CONST_VALUE}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(CONST_VALUE IN LISTS CONST_VALUES)
|
|
|
|
string(LENGTH "${CONST_VALUE}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQConst(engine, ${CLS}::${CONST_VALUE},${SPACES}\"${CONST_VALUE}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Mapping of OTTD strings to errors
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(ENUM_STRING_TO_ERROR IN LISTS ENUM_STRING_TO_ERRORS)
|
|
|
|
string(REPLACE ":" ";" ENUM_STRING_TO_ERROR "${ENUM_STRING_TO_ERROR}")
|
|
|
|
list(GET ENUM_STRING_TO_ERROR 0 ENUM_STRING)
|
|
|
|
string(LENGTH "${ENUM_STRING}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(ENUM_STRING_TO_ERROR IN LISTS ENUM_STRING_TO_ERRORS)
|
|
|
|
string(REPLACE ":" ";" ENUM_STRING_TO_ERROR "${ENUM_STRING_TO_ERROR}")
|
|
|
|
list(GET ENUM_STRING_TO_ERROR 0 ENUM_STRING)
|
|
|
|
list(GET ENUM_STRING_TO_ERROR 1 ENUM_ERROR)
|
|
|
|
string(LENGTH "${ENUM_STRING}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n ScriptError::RegisterErrorMap(${ENUM_STRING},${SPACES}${CLS}::${ENUM_ERROR});")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Mapping of errors to human 'readable' strings.
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(ENUM_ERROR_TO_STRING IN LISTS ENUM_ERROR_TO_STRINGS)
|
|
|
|
string(LENGTH "${ENUM_ERROR_TO_STRING}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(ENUM_ERROR_TO_STRING IN LISTS ENUM_ERROR_TO_STRINGS)
|
|
|
|
string(LENGTH "${ENUM_ERROR_TO_STRING}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n ScriptError::RegisterErrorMapString(${CLS}::${ENUM_ERROR_TO_STRING},${SPACES}\"${ENUM_ERROR_TO_STRING}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Static methods
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(STATIC_METHOD IN LISTS STATIC_METHODS)
|
|
|
|
string(REPLACE ":" ";" STATIC_METHOD "${STATIC_METHOD}")
|
|
|
|
list(GET STATIC_METHOD 0 FUNCNAME)
|
|
|
|
string(LENGTH "${FUNCNAME}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(STATIC_METHOD IN LISTS STATIC_METHODS)
|
|
|
|
string(REPLACE ":" ";" STATIC_METHOD "${STATIC_METHOD}")
|
|
|
|
list(GET STATIC_METHOD 0 FUNCNAME)
|
|
|
|
list(GET STATIC_METHOD 1 ARGC)
|
|
|
|
list(GET STATIC_METHOD 2 TYPES)
|
|
|
|
string(LENGTH "${FUNCNAME}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${TYPES}" STREQUAL "v")
|
|
|
|
if(LEN GREATER 8)
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR LEN "${LEN} - 8")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(LEN 0)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if("${TYPES}" STREQUAL "v")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Non-static methods
|
|
|
|
set(MLEN 0)
|
|
|
|
foreach(METHOD IN LISTS METHODS)
|
|
|
|
string(REPLACE ":" ";" METHOD "${METHOD}")
|
|
|
|
list(GET METHOD 0 FUNCNAME)
|
|
|
|
string(LENGTH "${FUNCNAME}" LEN)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MLEN LESS LEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(MLEN ${LEN})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
foreach(METHOD IN LISTS METHODS)
|
|
|
|
string(REPLACE ":" ";" METHOD "${METHOD}")
|
|
|
|
list(GET METHOD 0 FUNCNAME)
|
|
|
|
list(GET METHOD 1 ARGC)
|
|
|
|
list(GET METHOD 2 TYPES)
|
|
|
|
string(LENGTH "${FUNCNAME}" LEN)
|
|
|
|
math(EXPR LEN "${MLEN} - ${LEN}")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${TYPES}" STREQUAL "v")
|
|
|
|
if(LEN GREATER 8)
|
2019-03-12 14:37:57 +00:00
|
|
|
math(EXPR LEN "${LEN} - 8")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(LEN 0)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(SPACES)
|
|
|
|
foreach(i RANGE ${LEN})
|
|
|
|
string(APPEND SPACES " ")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
if("${TYPES}" STREQUAL "v")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(MLEN)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND SQUIRREL_EXPORT "\n")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PostRegister(engine);")
|
|
|
|
string(APPEND SQUIRREL_EXPORT "\n}")
|
|
|
|
|
|
|
|
reset_reader()
|
|
|
|
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Skip non-public functions
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT IS_PUBLIC)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Add enums
|
2020-09-25 11:55:25 +00:00
|
|
|
if(IN_ENUM)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(REGEX MATCH "([^, ]+)" ENUM_VALUE "${LINE}")
|
|
|
|
list(APPEND ENUM_VALUES "${ENUM_VALUE}")
|
|
|
|
|
|
|
|
# Check if this a special error enum
|
|
|
|
list(GET ENUMS -1 ENUM)
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${ENUM}" MATCHES ".*::ErrorMessages")
|
2019-03-12 14:37:57 +00:00
|
|
|
# syntax:
|
|
|
|
# enum ErrorMessages {
|
|
|
|
# ERR_SOME_ERROR, // [STR_ITEM1, STR_ITEM2, ...]
|
|
|
|
# }
|
|
|
|
|
|
|
|
# Set the mappings
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "\\[(.*)\\]")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(REGEX REPLACE "[ ]" "" MAPPINGS "${CMAKE_MATCH_1}")
|
|
|
|
string(REPLACE "," ";" MAPPINGS "${MAPPINGS}")
|
|
|
|
|
|
|
|
foreach(MAPPING IN LISTS MAPPINGS)
|
|
|
|
list(APPEND ENUM_STRING_TO_ERRORS "${MAPPING}:${ENUM_VALUE}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
list(APPEND ENUM_ERROR_TO_STRINGS "${ENUM_VALUE}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Add a const (non-enum) value
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^[ ]*static const [^ ]+ ([^ ]+) = -?\\(?[^ ]*\\)?[^ ]+;")
|
2019-03-12 14:37:57 +00:00
|
|
|
list(APPEND CONST_VALUES "${CMAKE_MATCH_1}")
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Add a method to the list
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "^.*\\(.*\\).*$")
|
|
|
|
if(NOT CLS_LEVEL EQUAL 1)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if("${LINE}" MATCHES "~")
|
|
|
|
if(DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(WARNING "Destructor for '${CLS}' has @api. Tag ignored.")
|
|
|
|
unset(API_SELECTED)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
unset(IS_STATIC)
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "static")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(IS_STATIC TRUE)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
string(REGEX REPLACE "(virtual|static|const)[ ]+" "" LINE "${LINE}")
|
|
|
|
string(REGEX REPLACE "{.*" "" LINE "${LINE}")
|
|
|
|
set(PARAM_S "${LINE}")
|
|
|
|
string(REGEX REPLACE "\\*" "" LINE "${LINE}")
|
|
|
|
string(REGEX REPLACE "\\(.*" "" LINE "${LINE}")
|
|
|
|
|
|
|
|
string(REGEX REPLACE ".*\\(" "" PARAM_S "${PARAM_S}")
|
|
|
|
string(REGEX REPLACE "\\).*" "" PARAM_S "${PARAM_S}")
|
|
|
|
|
|
|
|
string(REGEX MATCH "([^ ]+)( ([^ ]+))?" RESULT "${LINE}")
|
|
|
|
set(FUNCTYPE "${CMAKE_MATCH_1}")
|
|
|
|
set(FUNCNAME "${CMAKE_MATCH_3}")
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
|
|
|
if(DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(WARNING "Constructor for '${CLS}' has @api. Tag ignored.")
|
|
|
|
unset(API_SELECTED)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(CLS_PARAM_0 "${PARAM_S}")
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT PARAM_S)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
elseif(NOT FUNCNAME)
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
string(REPLACE "," ";" PARAMS "${PARAM_S}")
|
2020-09-25 11:55:25 +00:00
|
|
|
if(IS_STATIC)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(TYPES ".")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
set(TYPES "x")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
set(LEN 1)
|
|
|
|
foreach(PARAM IN LISTS PARAMS)
|
|
|
|
math(EXPR LEN "${LEN} + 1")
|
|
|
|
string(STRIP "${PARAM}" PARAM)
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${PARAM}" MATCHES "\\*|&")
|
|
|
|
if("${PARAM}" MATCHES "^char")
|
2019-03-12 14:37:57 +00:00
|
|
|
# Many types can be converted to string, so use '.', not 's'. (handled by our glue code)
|
|
|
|
string(APPEND TYPES ".")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^void")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "p")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^Array")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "a")
|
2023-02-23 23:49:57 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^const Array")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "a")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^Text")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES ".")
|
2023-05-05 17:31:06 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^std::string")
|
|
|
|
string(APPEND TYPES ".")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "x")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
elseif("${PARAM}" MATCHES "^bool")
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "b")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${PARAM}" MATCHES "^HSQUIRRELVM")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(TYPES "v")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(APPEND TYPES "i")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
# Check if we want to publish this function
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT DEFINED API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(API_SELECTED ${CLS_IN_API})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT API_SELECTED)
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
unset(API_SELECTED)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
2019-03-12 14:37:57 +00:00
|
|
|
set(CLS_PARAM_1 ${LEN})
|
|
|
|
set(CLS_PARAM_2 "${TYPES}")
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v")
|
|
|
|
elseif(IS_STATIC)
|
2019-03-12 14:37:57 +00:00
|
|
|
list(APPEND STATIC_METHODS "${FUNCNAME}:${LEN}:${TYPES}")
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
2019-03-12 14:37:57 +00:00
|
|
|
list(APPEND METHODS "${FUNCNAME}:${LEN}:${TYPES}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2024-01-05 16:52:13 +00:00
|
|
|
doxygen_check()
|
|
|
|
|
2019-03-12 14:37:57 +00:00
|
|
|
configure_file(${SCRIPT_API_SOURCE_FILE} ${SCRIPT_API_BINARY_FILE})
|