Merge branch 'openttd'
This commit is contained in:
@@ -17,41 +17,48 @@ if(NOT APILC)
|
||||
endif()
|
||||
|
||||
macro(dump_fileheader)
|
||||
get_filename_component(SCRIPT_API_FILE_NAME "${SCRIPT_API_FILE}" NAME)
|
||||
string(APPEND SQUIRREL_EXPORT "\n#include \"../${SCRIPT_API_FILE_NAME}\"")
|
||||
get_filename_component(SCRIPT_API_FILE_NAME "${SCRIPT_API_FILE}" NAME_WE)
|
||||
string(APPEND SQUIRREL_EXPORT "\n#include \"../${SCRIPT_API_FILE_NAME}.hpp\"")
|
||||
if(NOT "${APIUC}" STREQUAL "Template")
|
||||
string(REPLACE "script_" "template_" SCRIPT_API_FILE_NAME "${SCRIPT_API_FILE_NAME}")
|
||||
string(APPEND SQUIRREL_EXPORT "\n#include \"../template/${SCRIPT_API_FILE_NAME}.sq\"")
|
||||
string(APPEND SQUIRREL_EXPORT "\n#include \"../template/${SCRIPT_API_FILE_NAME}.sq.hpp\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(open_namespace)
|
||||
if(NOT NAMESPACE_OPENED)
|
||||
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
||||
set(NAMESPACE_OPENED TRUE)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(dump_class_templates NAME)
|
||||
string(REGEX REPLACE "^Script" "" REALNAME ${NAME})
|
||||
|
||||
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<${NAME} *> { static inline ${NAME} *Get(HSQUIRRELVM vm, int index) { return static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<${NAME} &> { static inline ${NAME} &Get(HSQUIRRELVM vm, int index) { return *static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<const ${NAME} *> { static inline const ${NAME} *Get(HSQUIRRELVM vm, int index) { return static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<const ${NAME} &> { static inline const ${NAME} &Get(HSQUIRRELVM vm, int index) { return *static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> struct Param<${NAME} *> { static inline ${NAME} *Get(HSQUIRRELVM vm, int index) { return static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> struct Param<${NAME} &> { static inline ${NAME} &Get(HSQUIRRELVM vm, int index) { return *static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> struct Param<const ${NAME} *> { static inline const ${NAME} *Get(HSQUIRRELVM vm, int index) { return static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> struct Param<const ${NAME} &> { static inline const ${NAME} &Get(HSQUIRRELVM vm, int index) { return *static_cast<${NAME} *>(Squirrel::GetRealInstance(vm, index, \"${REALNAME}\")); } };")
|
||||
if("${NAME}" STREQUAL "ScriptEvent")
|
||||
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; } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> 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; } };")
|
||||
elseif("${NAME}" STREQUAL "ScriptText")
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
string(APPEND SQUIRREL_EXPORT "\n template <> struct Param<Text *> {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n static inline Text *Get(HSQUIRRELVM vm, int index) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n if (sq_gettype(vm, index) == OT_INSTANCE) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n return Param<ScriptText *>::Get(vm, index);")
|
||||
string(APPEND SQUIRREL_EXPORT "\n }")
|
||||
string(APPEND SQUIRREL_EXPORT "\n if (sq_gettype(vm, index) == OT_STRING) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n return new RawText(Param<const std::string &>::Get(vm, index));")
|
||||
string(APPEND SQUIRREL_EXPORT "\n }")
|
||||
string(APPEND SQUIRREL_EXPORT "\n if (sq_gettype(vm, index) == OT_NULL) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n return nullptr;")
|
||||
string(APPEND SQUIRREL_EXPORT "\n }")
|
||||
string(APPEND SQUIRREL_EXPORT "\n throw sq_throwerror(vm, fmt::format(\"parameter {} has an invalid type ; expected: 'Text'\", index - 1));")
|
||||
string(APPEND SQUIRREL_EXPORT "\n }")
|
||||
string(APPEND SQUIRREL_EXPORT "\n };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> struct Param<Text *> {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\tstatic inline Text *Get(HSQUIRRELVM vm, int index) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\tif (sq_gettype(vm, index) == OT_INSTANCE) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t\treturn Param<ScriptText *>::Get(vm, index);")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t}")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\tif (sq_gettype(vm, index) == OT_STRING) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t\treturn new RawText(Param<const std::string &>::Get(vm, index));")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t}")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\tif (sq_gettype(vm, index) == OT_NULL) {")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t\treturn nullptr;")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\t}")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t\tthrow sq_throwerror(vm, fmt::format(\"parameter {} has an invalid type ; expected: 'Text'\", index - 1));")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t\t}")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t};")
|
||||
else()
|
||||
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; } };")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\ttemplate <> 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; } };")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
@@ -66,7 +73,6 @@ macro(reset_reader)
|
||||
unset(STATIC_METHODS)
|
||||
unset(CLS)
|
||||
unset(START_SQUIRREL_DEFINE_ON_NEXT_LINE)
|
||||
set(CLS_LEVEL 0)
|
||||
unset(CLS_IN_API)
|
||||
endmacro()
|
||||
|
||||
@@ -75,6 +81,9 @@ reset_reader()
|
||||
file(STRINGS "${SCRIPT_API_FILE}" SOURCE_LINES)
|
||||
|
||||
set(NUM_LINE 0)
|
||||
set(CLS_LEVEL 0)
|
||||
set(BRACE_LEVEL 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")
|
||||
@@ -110,7 +119,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
if("${LINE}" MATCHES "^([ ]*)\\* @api (.*)$")
|
||||
if("${LINE}" MATCHES "^([\t ]*)\\* @api (.*)$")
|
||||
set(LINE ${CMAKE_MATCH_2})
|
||||
# By default, classes are not selected
|
||||
if(NOT CLS_LEVEL)
|
||||
@@ -148,22 +157,28 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
# Count braces to skip function bodies
|
||||
string(REGEX REPLACE "[^{]" "" OPENING_BRACES "${LINE}")
|
||||
string(LENGTH "${OPENING_BRACES}" OPENING_BRACES)
|
||||
string(REGEX REPLACE "[^}]" "" CLOSING_BRACES "${LINE}")
|
||||
string(LENGTH "${CLOSING_BRACES}" CLOSING_BRACES)
|
||||
math(EXPR BRACE_LEVEL "${BRACE_LEVEL} + ${OPENING_BRACES} - ${CLOSING_BRACES}")
|
||||
|
||||
# Ignore forward declarations of classes
|
||||
if("${LINE}" MATCHES "^( *)class(.*);")
|
||||
if("${LINE}" MATCHES "^(\t*)class(.*);")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
# We only want to have public functions exported for now
|
||||
if("${LINE}" MATCHES "^( *)class (.*) (: public|: protected|: private|:) ([^ ]*)")
|
||||
if("${LINE}" MATCHES "^(\t*)class (.*) (: public|: protected|: private|:) ([^ ]*)")
|
||||
if(NOT CLS_LEVEL)
|
||||
if(NOT DEFINED API_SELECTED)
|
||||
message(WARNING "Class '${CMAKE_MATCH_2}' has no @api. It won't be published to any API.")
|
||||
message(WARNING "${SCRIPT_API_FILE}:${NUM_LINE}: Class '${CMAKE_MATCH_2}' has no @api. It won't be published to any API.")
|
||||
set(API_SELECTED FALSE)
|
||||
endif()
|
||||
unset(IS_PUBLIC)
|
||||
unset(CLS_PARAM_0)
|
||||
set(CLS_PARAM_1 1)
|
||||
set(CLS_PARAM_2 "x")
|
||||
unset(CLS_PARAMS)
|
||||
set(CLS_TYPES "x")
|
||||
set(CLS_IN_API ${API_SELECTED})
|
||||
unset(API_SELECTED)
|
||||
set(CLS "${CMAKE_MATCH_2}")
|
||||
@@ -181,19 +196,19 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
||||
continue()
|
||||
endif()
|
||||
if("${LINE}" MATCHES "^( *)public")
|
||||
if("${LINE}" MATCHES "^(\t*)public")
|
||||
if(CLS_LEVEL EQUAL 1)
|
||||
set(IS_PUBLIC TRUE)
|
||||
endif()
|
||||
continue()
|
||||
endif()
|
||||
if("${LINE}" MATCHES "^( *)protected")
|
||||
if("${LINE}" MATCHES "^(\t*)protected")
|
||||
if(CLS_LEVEL EQUAL 1)
|
||||
unset(IS_PUBLIC)
|
||||
endif()
|
||||
continue()
|
||||
endif()
|
||||
if("${LINE}" MATCHES "^( *)private")
|
||||
if("${LINE}" MATCHES "^(\t*)private")
|
||||
if(CLS_LEVEL EQUAL 1)
|
||||
unset(IS_PUBLIC)
|
||||
endif()
|
||||
@@ -221,7 +236,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
# We need to make specialized conversions for structs
|
||||
if("${LINE}" MATCHES "^( *)struct ([^ ]*)")
|
||||
if("${LINE}" MATCHES "^(\t*)struct ([^ ]*)")
|
||||
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
||||
|
||||
# Check if we want to publish this struct
|
||||
@@ -243,7 +258,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
# We need to make specialized conversions for enums
|
||||
if("${LINE}" MATCHES "^( *)enum ([^ ]*)")
|
||||
if("${LINE}" MATCHES "^(\t*)enum ([^ ]*)")
|
||||
math(EXPR CLS_LEVEL "${CLS_LEVEL} + 1")
|
||||
|
||||
# Check if we want to publish this enum
|
||||
@@ -266,7 +281,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
# Maybe the end of the class, if so we can start with the Squirrel export pretty soon
|
||||
if("${LINE}" MATCHES "};")
|
||||
if(BRACE_LEVEL LESS CLS_LEVEL)
|
||||
math(EXPR CLS_LEVEL "${CLS_LEVEL} - 1")
|
||||
if(CLS_LEVEL)
|
||||
unset(IN_ENUM)
|
||||
@@ -280,7 +295,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
# Empty/white lines. When we may do the Squirrel export, do that export.
|
||||
if("${LINE}" MATCHES "^([ ]*)$")
|
||||
if("${LINE}" MATCHES "^([ \t]*)$")
|
||||
if(NOT START_SQUIRREL_DEFINE_ON_NEXT_LINE)
|
||||
continue()
|
||||
endif()
|
||||
@@ -304,33 +319,17 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
|
||||
if("${APIUC}" STREQUAL "Template")
|
||||
# First check whether we have enums to print
|
||||
if(DEFINED ENUMS)
|
||||
if(NOT NAMESPACE_OPENED)
|
||||
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
||||
set(NAMESPACE_OPENED TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Then check whether we have structs/classes to print
|
||||
if(DEFINED STRUCTS)
|
||||
if(NOT NAMESPACE_OPENED)
|
||||
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
||||
set(NAMESPACE_OPENED TRUE)
|
||||
endif()
|
||||
string(APPEND SQUIRREL_EXPORT "\n /* Allow inner classes/structs to be used as Squirrel parameters */")
|
||||
open_namespace()
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t/* Allow inner classes/structs to be used as Squirrel parameters */")
|
||||
foreach(STRUCT IN LISTS STRUCTS)
|
||||
dump_class_templates(${STRUCT})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(NOT NAMESPACE_OPENED)
|
||||
string(APPEND SQUIRREL_EXPORT "\nnamespace SQConvert {")
|
||||
set(NAMESPACE_OPENED TRUE)
|
||||
else()
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
endif()
|
||||
string(APPEND SQUIRREL_EXPORT "\n /* Allow ${CLS} to be used as Squirrel parameter */")
|
||||
open_namespace()
|
||||
string(APPEND SQUIRREL_EXPORT "\n\t/* Allow ${CLS} to be used as Squirrel parameter */")
|
||||
dump_class_templates(${CLS})
|
||||
|
||||
string(APPEND SQUIRREL_EXPORT "\n} // namespace SQConvert")
|
||||
@@ -340,23 +339,23 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
string(APPEND SQUIRREL_EXPORT "\ntemplate <> SQInteger PushClassName<${CLS}, ScriptType::${APIUC}>(HSQUIRRELVM vm) { sq_pushstring(vm, \"${API_CLS}\", -1); return 1; }")
|
||||
string(APPEND SQUIRREL_EXPORT "\ntemplate <> SQInteger PushClassName<${CLS}, ScriptType::${APIUC}>(HSQUIRRELVM vm) { sq_pushstring(vm, \"${API_CLS}\"); return 1; }")
|
||||
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 "\nvoid SQ${API_CLS}_Register(Squirrel &engine)")
|
||||
string(APPEND SQUIRREL_EXPORT "\n{")
|
||||
string(APPEND SQUIRREL_EXPORT "\n DefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tDefSQClass<${CLS}, ScriptType::${APIUC}> SQ${API_CLS}(\"${API_CLS}\");")
|
||||
if("${SUPER_CLS}" STREQUAL "Text")
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine);")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.PreRegister(engine);")
|
||||
else()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PreRegister(engine, \"${API_SUPER_CLS}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.PreRegister(engine, \"${API_SUPER_CLS}\");")
|
||||
endif()
|
||||
if(NOT "${SUPER_CLS}" MATCHES "^ScriptEvent")
|
||||
if("${CLS_PARAM_2}" STREQUAL "v")
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.AddSQAdvancedConstructor(engine);")
|
||||
if((DEFINED CLS_PARAMS OR DEFINED METHODS) AND NOT "${SUPER_CLS}" MATCHES "^ScriptEvent" AND NOT "${CLS}" STREQUAL "ScriptEvent")
|
||||
if("${CLS_TYPES}" STREQUAL "v")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddSQAdvancedConstructor(engine);")
|
||||
else()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.AddConstructor<void (${CLS}::*)(${CLS_PARAM_0}), ${CLS_PARAM_1}>(engine, \"${CLS_PARAM_2}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.AddConstructor<void (${CLS}::*)(${CLS_PARAMS})>(engine, \"${CLS_TYPES}\");")
|
||||
endif()
|
||||
endif()
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
@@ -376,7 +375,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
foreach(i RANGE ${LEN})
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQConst(engine, ${CLS}::${ENUM_VALUE},${SPACES}\"${ENUM_VALUE}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQConst(engine, ${CLS}::${ENUM_VALUE},${SPACES}\"${ENUM_VALUE}\");")
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
@@ -397,7 +396,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
foreach(i RANGE ${LEN})
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQConst(engine, ${CLS}::${CONST_VALUE},${SPACES}\"${CONST_VALUE}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQConst(engine, ${CLS}::${CONST_VALUE},${SPACES}\"${CONST_VALUE}\");")
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
@@ -423,7 +422,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
foreach(i RANGE ${LEN})
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
string(APPEND SQUIRREL_EXPORT "\n ScriptError::RegisterErrorMap(${ENUM_STRING},${SPACES}${CLS}::${ENUM_ERROR});")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tScriptError::RegisterErrorMap(${ENUM_STRING},${SPACES}${CLS}::${ENUM_ERROR});")
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
@@ -444,7 +443,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
foreach(i RANGE ${LEN})
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
string(APPEND SQUIRREL_EXPORT "\n ScriptError::RegisterErrorMapString(${CLS}::${ENUM_ERROR_TO_STRING},${SPACES}\"${ENUM_ERROR_TO_STRING}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tScriptError::RegisterErrorMapString(${CLS}::${ENUM_ERROR_TO_STRING},${SPACES}\"${ENUM_ERROR_TO_STRING}\");")
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
@@ -463,8 +462,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
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)
|
||||
list(GET STATIC_METHOD 1 TYPES)
|
||||
string(LENGTH "${FUNCNAME}" LEN)
|
||||
math(EXPR LEN "${MLEN} - ${LEN}")
|
||||
if("${TYPES}" STREQUAL "v")
|
||||
@@ -479,9 +477,9 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
if("${TYPES}" STREQUAL "v")
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQAdvancedStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
||||
else()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQStaticMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}\"${TYPES}\");")
|
||||
endif()
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
@@ -501,8 +499,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
foreach(METHOD IN LISTS METHODS)
|
||||
string(REPLACE ":" ";" METHOD "${METHOD}")
|
||||
list(GET METHOD 0 FUNCNAME)
|
||||
list(GET METHOD 1 ARGC)
|
||||
list(GET METHOD 2 TYPES)
|
||||
list(GET METHOD 1 TYPES)
|
||||
string(LENGTH "${FUNCNAME}" LEN)
|
||||
math(EXPR LEN "${MLEN} - ${LEN}")
|
||||
if("${TYPES}" STREQUAL "v")
|
||||
@@ -517,16 +514,16 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
string(APPEND SPACES " ")
|
||||
endforeach()
|
||||
if("${TYPES}" STREQUAL "v")
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQAdvancedMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQAdvancedMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\");")
|
||||
else()
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.DefSQMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}${ARGC}, \"${TYPES}\");")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.DefSQMethod(engine, &${CLS}::${FUNCNAME},${SPACES}\"${FUNCNAME}\",${SPACES}\"${TYPES}\");")
|
||||
endif()
|
||||
endforeach()
|
||||
if(MLEN)
|
||||
string(APPEND SQUIRREL_EXPORT "\n")
|
||||
endif()
|
||||
|
||||
string(APPEND SQUIRREL_EXPORT "\n SQ${API_CLS}.PostRegister(engine);")
|
||||
string(APPEND SQUIRREL_EXPORT "\n\tSQ${API_CLS}.PostRegister(engine);")
|
||||
string(APPEND SQUIRREL_EXPORT "\n}")
|
||||
|
||||
reset_reader()
|
||||
@@ -539,9 +536,13 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
if(NOT BRACE_LEVEL EQUAL CLS_LEVEL)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
# Add enums
|
||||
if(IN_ENUM)
|
||||
string(REGEX MATCH "([^, ]+)" ENUM_VALUE "${LINE}")
|
||||
string(REGEX MATCH "([^,\t ]+)" ENUM_VALUE "${LINE}")
|
||||
list(APPEND ENUM_VALUES "${ENUM_VALUE}")
|
||||
|
||||
# Check if this a special error enum
|
||||
@@ -549,12 +550,12 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
if("${ENUM}" MATCHES ".*::ErrorMessages")
|
||||
# syntax:
|
||||
# enum ErrorMessages {
|
||||
# ERR_SOME_ERROR, // [STR_ITEM1, STR_ITEM2, ...]
|
||||
#\tERR_SOME_ERROR,\t// [STR_ITEM1, STR_ITEM2, ...]
|
||||
# }
|
||||
|
||||
# Set the mappings
|
||||
if("${LINE}" MATCHES "\\[(.*)\\]")
|
||||
string(REGEX REPLACE "[ ]" "" MAPPINGS "${CMAKE_MATCH_1}")
|
||||
string(REGEX REPLACE "[ \t]" "" MAPPINGS "${CMAKE_MATCH_1}")
|
||||
string(REPLACE "," ";" MAPPINGS "${MAPPINGS}")
|
||||
|
||||
foreach(MAPPING IN LISTS MAPPINGS)
|
||||
@@ -568,11 +569,11 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
|
||||
# Add a const (non-enum) value
|
||||
if("${LINE}" MATCHES "^[ ]*static const [^ ]+ ([^ ]+) = -?\\(?[^ ]*\\)?[^ ]+;")
|
||||
if("${LINE}" MATCHES "^[ \t]*static const [^ ]+ ([^ ]+) = -?\\(?[^ ]*\\)?[^ ]+;")
|
||||
list(APPEND CONST_VALUES "${CMAKE_MATCH_1}")
|
||||
continue()
|
||||
endif()
|
||||
if("${LINE}" MATCHES "^[ ]*static constexpr [^ ]+ ([^ ]+) = -?\\(?[^ ]*\\)?[^ ]+;")
|
||||
if("${LINE}" MATCHES "^[ \t]*static constexpr [^ ]+ ([^ ]+) = -?\\(?[^ ]*\\)?[^ ]+;")
|
||||
list(APPEND CONST_VALUES "${CMAKE_MATCH_1}")
|
||||
continue()
|
||||
endif()
|
||||
@@ -584,41 +585,43 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
endif()
|
||||
if("${LINE}" MATCHES "~")
|
||||
if(DEFINED API_SELECTED)
|
||||
message(WARNING "Destructor for '${CLS}' has @api. Tag ignored.")
|
||||
message(WARNING "${SCRIPT_API_FILE}:${NUM_LINE}: Destructor for '${CLS}' has @api. Tag ignored.")
|
||||
unset(API_SELECTED)
|
||||
endif()
|
||||
continue()
|
||||
endif()
|
||||
|
||||
unset(IS_STATIC)
|
||||
if("${LINE}" MATCHES "static")
|
||||
if("${LINE}" MATCHES "static ")
|
||||
set(IS_STATIC TRUE)
|
||||
endif()
|
||||
|
||||
string(REGEX REPLACE "(virtual|static|const)[ ]+" "" LINE "${LINE}")
|
||||
string(REGEX REPLACE "(virtual|static|const)[ \t]+" "" 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}")
|
||||
# Parameters start at first "(". Further "(" will appear in ctor lists.
|
||||
string(REGEX MATCH "\\(.*" PARAM_S "${PARAM_S}")
|
||||
string(REGEX REPLACE "\\).*" "" PARAM_S "${PARAM_S}")
|
||||
string(REGEX REPLACE "^\\(" "" PARAM_S "${PARAM_S}")
|
||||
|
||||
string(REGEX MATCH "([^ ]+)( ([^ ]+))?" RESULT "${LINE}")
|
||||
string(REGEX MATCH "([^ \t]+)( ([^ ]+))?" RESULT "${LINE}")
|
||||
set(FUNCTYPE "${CMAKE_MATCH_1}")
|
||||
set(FUNCNAME "${CMAKE_MATCH_3}")
|
||||
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
||||
if(DEFINED API_SELECTED)
|
||||
message(WARNING "Constructor for '${CLS}' has @api. Tag ignored.")
|
||||
message(WARNING "${SCRIPT_API_FILE}:${NUM_LINE}: Constructor for '${CLS}' has @api. Tag ignored.")
|
||||
unset(API_SELECTED)
|
||||
endif()
|
||||
set(CLS_PARAM_0 "${PARAM_S}")
|
||||
set(CLS_PARAMS "${PARAM_S}")
|
||||
if(NOT PARAM_S)
|
||||
continue()
|
||||
endif()
|
||||
elseif(NOT FUNCNAME)
|
||||
continue()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
string(REPLACE "," ";" PARAMS "${PARAM_S}")
|
||||
if(IS_STATIC)
|
||||
@@ -627,9 +630,7 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
set(TYPES "x")
|
||||
endif()
|
||||
|
||||
set(LEN 1)
|
||||
foreach(PARAM IN LISTS PARAMS)
|
||||
math(EXPR LEN "${LEN} + 1")
|
||||
string(STRIP "${PARAM}" PARAM)
|
||||
if("${PARAM}" MATCHES "\\*|&")
|
||||
if("${PARAM}" MATCHES "^char")
|
||||
@@ -668,13 +669,12 @@ foreach(LINE IN LISTS SOURCE_LINES)
|
||||
unset(API_SELECTED)
|
||||
|
||||
if("${FUNCTYPE}" STREQUAL "${CLS}" AND NOT FUNCNAME)
|
||||
set(CLS_PARAM_1 ${LEN})
|
||||
set(CLS_PARAM_2 "${TYPES}")
|
||||
set(CLS_TYPES "${TYPES}")
|
||||
elseif("${FUNCNAME}" MATCHES "^_" AND NOT "${TYPES}" STREQUAL "v")
|
||||
elseif(IS_STATIC)
|
||||
list(APPEND STATIC_METHODS "${FUNCNAME}:${LEN}:${TYPES}")
|
||||
list(APPEND STATIC_METHODS "${FUNCNAME}:${TYPES}")
|
||||
else()
|
||||
list(APPEND METHODS "${FUNCNAME}:${LEN}:${TYPES}")
|
||||
list(APPEND METHODS "${FUNCNAME}:${TYPES}")
|
||||
endif()
|
||||
continue()
|
||||
endif()
|
||||
|
||||
@@ -19,7 +19,7 @@ endif()
|
||||
file(READ "${API_FILES}" SCRIPT_API_BINARY_FILES)
|
||||
|
||||
foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES)
|
||||
file(STRINGS "${FILE}" LINES REGEX "^void SQ${APIUC}.*_Register\\(Squirrel \\*engine\\)$")
|
||||
file(STRINGS "${FILE}" LINES REGEX "^void SQ${APIUC}.*_Register\\(Squirrel &engine\\)$")
|
||||
if(LINES)
|
||||
string(REGEX REPLACE ".*api/${APILC}/(.*)" "#include \"\\1\"" FILE "${FILE}")
|
||||
list(APPEND SQUIRREL_INCLUDES "${FILE}")
|
||||
@@ -28,7 +28,7 @@ foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES)
|
||||
continue()
|
||||
endif()
|
||||
string(REGEX REPLACE "^.*void " " " LINE "${LINE}")
|
||||
string(REGEX REPLACE "Squirrel \\*" "" LINE "${LINE}")
|
||||
string(REGEX REPLACE "Squirrel &" "" LINE "${LINE}")
|
||||
list(APPEND SQUIRREL_REGISTER "${LINE}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user