Move all dependencies over to CPM
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
c960f3fa0b
commit
b7c27cb1f8
|
@ -37,18 +37,6 @@ CPMAddPackage(
|
||||||
)
|
)
|
||||||
execute_process(COMMAND ln -sf ${Arbutils_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include/Arbutils)
|
execute_process(COMMAND ln -sf ${Arbutils_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include/Arbutils)
|
||||||
|
|
||||||
|
|
||||||
CPMAddPackage(
|
|
||||||
NAME CreatureLib
|
|
||||||
GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/CreatureLib.git
|
|
||||||
GIT_TAG master
|
|
||||||
OPTIONS
|
|
||||||
"SHARED=${SHARED}"
|
|
||||||
"WINDOWS=${WINDOWS}"
|
|
||||||
"STATICC=${STATICC}"
|
|
||||||
)
|
|
||||||
execute_process(COMMAND ln -sf ${CreatureLib_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include/CreatureLib)
|
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME CreatureLib
|
NAME CreatureLib
|
||||||
GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/CreatureLib.git
|
GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/CreatureLib.git
|
||||||
|
@ -80,6 +68,7 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript")
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||||
include_directories(${Angelscript_SOURCE_DIR}/angelscript/include)
|
include_directories(${Angelscript_SOURCE_DIR}/angelscript/include)
|
||||||
|
include_directories(${Angelscript_SOURCE_DIR}/add_on)
|
||||||
link_directories(${Angelscript_BINARY_DIR})
|
link_directories(${Angelscript_BINARY_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -144,13 +133,24 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript")
|
||||||
SET(FILE_SOURCE ${FILE_SOURCE}
|
SET(FILE_SOURCE ${FILE_SOURCE}
|
||||||
"src/ScriptResolving/AngelScript/*.cpp"
|
"src/ScriptResolving/AngelScript/*.cpp"
|
||||||
"src/ScriptResolving/AngelScript/*.hpp"
|
"src/ScriptResolving/AngelScript/*.hpp"
|
||||||
"extern/angelscript_addons/*.cpp"
|
"${Angelscript_SOURCE_DIR}/add_on/scriptbuilder/scriptbuilder.cpp"
|
||||||
"extern/angelscript_addons/*.h"
|
"${Angelscript_SOURCE_DIR}/add_on/scripthelper/scripthelper.cpp"
|
||||||
|
"${Angelscript_SOURCE_DIR}/add_on/scripthandle/scripthandle.cpp"
|
||||||
|
"${Angelscript_SOURCE_DIR}/add_on/scriptstdstring/scriptstdstring.cpp"
|
||||||
|
"${Angelscript_SOURCE_DIR}/add_on/scriptdictionary/scriptdictionary.cpp"
|
||||||
|
"${Angelscript_SOURCE_DIR}/add_on/scriptarray/scriptarray.cpp"
|
||||||
"CInterface/AngelScript/*.cpp"
|
"CInterface/AngelScript/*.cpp"
|
||||||
"CInterface/AngelScript/*.hpp"
|
"CInterface/AngelScript/*.hpp"
|
||||||
)
|
)
|
||||||
if (ANGELSCRIPT_DEBUGGER)
|
if (ANGELSCRIPT_DEBUGGER)
|
||||||
SET(FILE_SOURCE ${FILE_SOURCE} "extern/AngelscriptDebuggerServer/src/*.cpp")
|
CPMAddPackage(
|
||||||
|
NAME AngelscriptDebugger
|
||||||
|
GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/AngelscriptDebuggerServer.git
|
||||||
|
GIT_TAG master
|
||||||
|
)
|
||||||
|
execute_process(COMMAND ln -sf ${AngelscriptDebugger_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include/AngelscriptDebuggerServer)
|
||||||
|
set(_LINKS ${_LINKS} AngelscriptDebugger)
|
||||||
|
set(_TESTLINKS ${_TESTLINKS} AngelscriptDebugger)
|
||||||
endif()
|
endif()
|
||||||
ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1)
|
ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1)
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -168,8 +168,8 @@ if (IPO_SUPPORTED)
|
||||||
set_property(TARGET pkmnLib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
set_property(TARGET pkmnLib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
SET(_LINKS CreatureLib Arbutils)
|
SET(_LINKS ${_LINKS} CreatureLib Arbutils)
|
||||||
SET(_TESTLINKS pkmnLib CreatureLib Arbutils)
|
SET(_TESTLINKS ${_TESTLINKS} pkmnLib CreatureLib Arbutils)
|
||||||
|
|
||||||
if (SCRIPT_PROVIDER STREQUAL "angelscript")
|
if (SCRIPT_PROVIDER STREQUAL "angelscript")
|
||||||
message(STATUS "Using Angelscript as script provider.")
|
message(STATUS "Using Angelscript as script provider.")
|
||||||
|
@ -210,14 +210,23 @@ endif ()
|
||||||
target_link_libraries(pkmnLib PRIVATE ${_LINKS})
|
target_link_libraries(pkmnLib PRIVATE ${_LINKS})
|
||||||
|
|
||||||
if (PKMNLIB_TESTS)
|
if (PKMNLIB_TESTS)
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME doctest
|
||||||
|
GITHUB_REPOSITORY doctest/doctest
|
||||||
|
GIT_TAG 2.4.0
|
||||||
|
DOWNLOAD_ONLY YES
|
||||||
|
)
|
||||||
|
|
||||||
# Create Test executable
|
# Create Test executable
|
||||||
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
||||||
add_executable(pkmnLibTests ${TEST_FILES} extern/doctest.hpp)
|
add_executable(pkmnLibTests ${TEST_FILES})
|
||||||
# Enable all warnings, and make them error when occurring.
|
# Enable all warnings, and make them error when occurring.
|
||||||
target_compile_options(pkmnLibTests PRIVATE -Wall -Wextra -Werror)
|
target_compile_options(pkmnLibTests PRIVATE -Wall -Wextra -Werror)
|
||||||
|
|
||||||
message(STATUS "${_TESTLINKS}")
|
message(STATUS "${_TESTLINKS}")
|
||||||
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})
|
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})
|
||||||
|
target_include_directories(pkmnLibTests PUBLIC ${doctest_SOURCE_DIR}/doctest)
|
||||||
|
|
||||||
|
|
||||||
# Add a definition for the test library
|
# Add a definition for the test library
|
||||||
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
|
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 2fe2286df8f790ef75702a517c1751972da364c5
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,142 +0,0 @@
|
||||||
#ifndef SCRIPTARRAY_H
|
|
||||||
#define SCRIPTARRAY_H
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Sometimes it may be desired to use the same method names as used by C++ STL.
|
|
||||||
// This may for example reduce time when converting code from script to C++ or
|
|
||||||
// back.
|
|
||||||
//
|
|
||||||
// 0 = off
|
|
||||||
// 1 = on
|
|
||||||
#ifndef AS_USE_STLNAMES
|
|
||||||
#define AS_USE_STLNAMES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Some prefer to use property accessors to get/set the length of the array
|
|
||||||
// This option registers the accessors instead of the method length()
|
|
||||||
#ifndef AS_USE_ACCESSORS
|
|
||||||
#define AS_USE_ACCESSORS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
struct SArrayBuffer;
|
|
||||||
struct SArrayCache;
|
|
||||||
|
|
||||||
class CScriptArray
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Set the memory functions that should be used by all CScriptArrays
|
|
||||||
static void SetMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
|
|
||||||
|
|
||||||
// Factory functions
|
|
||||||
static CScriptArray *Create(asITypeInfo *ot);
|
|
||||||
static CScriptArray *Create(asITypeInfo *ot, asUINT length);
|
|
||||||
static CScriptArray *Create(asITypeInfo *ot, asUINT length, void *defaultValue);
|
|
||||||
static CScriptArray *Create(asITypeInfo *ot, void *listBuffer);
|
|
||||||
|
|
||||||
// Memory management
|
|
||||||
void AddRef() const;
|
|
||||||
void Release() const;
|
|
||||||
|
|
||||||
// Type information
|
|
||||||
asITypeInfo *GetArrayObjectType() const;
|
|
||||||
int GetArrayTypeId() const;
|
|
||||||
int GetElementTypeId() const;
|
|
||||||
|
|
||||||
// Get the current size
|
|
||||||
asUINT GetSize() const;
|
|
||||||
|
|
||||||
// Returns true if the array is empty
|
|
||||||
bool IsEmpty() const;
|
|
||||||
|
|
||||||
// Pre-allocates memory for elements
|
|
||||||
void Reserve(asUINT maxElements);
|
|
||||||
|
|
||||||
// Resize the array
|
|
||||||
void Resize(asUINT numElements);
|
|
||||||
|
|
||||||
// Get a pointer to an element. Returns 0 if out of bounds
|
|
||||||
void *At(asUINT index);
|
|
||||||
const void *At(asUINT index) const;
|
|
||||||
|
|
||||||
// Set value of an element.
|
|
||||||
// The value arg should be a pointer to the value that will be copied to the element.
|
|
||||||
// Remember, if the array holds handles the value parameter should be the
|
|
||||||
// address of the handle. The refCount of the object will also be incremented
|
|
||||||
void SetValue(asUINT index, void *value);
|
|
||||||
|
|
||||||
// Copy the contents of one array to another (only if the types are the same)
|
|
||||||
CScriptArray &operator=(const CScriptArray&);
|
|
||||||
|
|
||||||
// Compare two arrays
|
|
||||||
bool operator==(const CScriptArray &) const;
|
|
||||||
|
|
||||||
// Array manipulation
|
|
||||||
void InsertAt(asUINT index, void *value);
|
|
||||||
void InsertAt(asUINT index, const CScriptArray &arr);
|
|
||||||
void InsertLast(void *value);
|
|
||||||
void RemoveAt(asUINT index);
|
|
||||||
void RemoveLast();
|
|
||||||
void RemoveRange(asUINT start, asUINT count);
|
|
||||||
void SortAsc();
|
|
||||||
void SortDesc();
|
|
||||||
void SortAsc(asUINT startAt, asUINT count);
|
|
||||||
void SortDesc(asUINT startAt, asUINT count);
|
|
||||||
void Sort(asUINT startAt, asUINT count, bool asc);
|
|
||||||
void Sort(asIScriptFunction *less, asUINT startAt, asUINT count);
|
|
||||||
void Reverse();
|
|
||||||
int Find(void *value) const;
|
|
||||||
int Find(asUINT startAt, void *value) const;
|
|
||||||
int FindByRef(void *ref) const;
|
|
||||||
int FindByRef(asUINT startAt, void *ref) const;
|
|
||||||
|
|
||||||
// Return the address of internal buffer for direct manipulation of elements
|
|
||||||
void *GetBuffer();
|
|
||||||
|
|
||||||
// GC methods
|
|
||||||
int GetRefCount();
|
|
||||||
void SetFlag();
|
|
||||||
bool GetFlag();
|
|
||||||
void EnumReferences(asIScriptEngine *engine);
|
|
||||||
void ReleaseAllHandles(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
mutable int refCount;
|
|
||||||
mutable bool gcFlag;
|
|
||||||
asITypeInfo *objType;
|
|
||||||
SArrayBuffer *buffer;
|
|
||||||
int elementSize;
|
|
||||||
int subTypeId;
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
CScriptArray(asITypeInfo *ot, void *initBuf); // Called from script when initialized with list
|
|
||||||
CScriptArray(asUINT length, asITypeInfo *ot);
|
|
||||||
CScriptArray(asUINT length, void *defVal, asITypeInfo *ot);
|
|
||||||
CScriptArray(const CScriptArray &other);
|
|
||||||
virtual ~CScriptArray();
|
|
||||||
|
|
||||||
bool Less(const void *a, const void *b, bool asc);
|
|
||||||
void *GetArrayItemPointer(int index);
|
|
||||||
void *GetDataPointer(void *buffer);
|
|
||||||
void Copy(void *dst, void *src);
|
|
||||||
void Precache();
|
|
||||||
bool CheckMaxSize(asUINT numElements);
|
|
||||||
void Resize(int delta, asUINT at);
|
|
||||||
void CreateBuffer(SArrayBuffer **buf, asUINT numElements);
|
|
||||||
void DeleteBuffer(SArrayBuffer *buf);
|
|
||||||
void CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src);
|
|
||||||
void Construct(SArrayBuffer *buf, asUINT start, asUINT end);
|
|
||||||
void Destruct(SArrayBuffer *buf, asUINT start, asUINT end);
|
|
||||||
bool Equals(const void *a, const void *b, asIScriptContext *ctx, SArrayCache *cache) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
void RegisterScriptArray(asIScriptEngine *engine, bool defaultArray);
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,216 +0,0 @@
|
||||||
#ifndef SCRIPTBUILDER_H
|
|
||||||
#define SCRIPTBUILDER_H
|
|
||||||
|
|
||||||
//---------------------------
|
|
||||||
// Compilation settings
|
|
||||||
//
|
|
||||||
|
|
||||||
// Set this flag to turn on/off metadata processing
|
|
||||||
// 0 = off
|
|
||||||
// 1 = on
|
|
||||||
#ifndef AS_PROCESS_METADATA
|
|
||||||
#define AS_PROCESS_METADATA 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: Implement flags for turning on/off include directives and conditional programming
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------
|
|
||||||
// Declaration
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1200
|
|
||||||
// disable the annoying warnings on MSVC 6
|
|
||||||
#pragma warning (disable:4786)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <vector>
|
|
||||||
#include <string.h> // _strcmpi
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
class CScriptBuilder;
|
|
||||||
|
|
||||||
// This callback will be called for each #include directive encountered by the
|
|
||||||
// builder. The callback should call the AddSectionFromFile or AddSectionFromMemory
|
|
||||||
// to add the included section to the script. If the include cannot be resolved
|
|
||||||
// then the function should return a negative value to abort the compilation.
|
|
||||||
typedef int (*INCLUDECALLBACK_t)(const char *include, const char *from, CScriptBuilder *builder, void *userParam);
|
|
||||||
|
|
||||||
// This callback will be called for each #pragma directive encountered by the builder.
|
|
||||||
// The application can interpret the pragmaText and decide what do to based on that.
|
|
||||||
// If the callback returns a negative value the builder will report an error and abort the compilation.
|
|
||||||
typedef int(*PRAGMACALLBACK_t)(const std::string &pragmaText, CScriptBuilder &builder, void *userParam);
|
|
||||||
|
|
||||||
// Helper class for loading and pre-processing script files to
|
|
||||||
// support include directives and metadata declarations
|
|
||||||
class CScriptBuilder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CScriptBuilder();
|
|
||||||
|
|
||||||
// Start a new module
|
|
||||||
int StartNewModule(asIScriptEngine *engine, const char *moduleName);
|
|
||||||
|
|
||||||
// Load a script section from a file on disk
|
|
||||||
// Returns 1 if the file was included
|
|
||||||
// 0 if the file had already been included before
|
|
||||||
// <0 on error
|
|
||||||
int AddSectionFromFile(const char *filename);
|
|
||||||
|
|
||||||
// Load a script section from memory
|
|
||||||
// Returns 1 if the section was included
|
|
||||||
// 0 if a section with the same name had already been included before
|
|
||||||
// <0 on error
|
|
||||||
int AddSectionFromMemory(const char *sectionName,
|
|
||||||
const char *scriptCode,
|
|
||||||
unsigned int scriptLength = 0,
|
|
||||||
int lineOffset = 0);
|
|
||||||
|
|
||||||
// Build the added script sections
|
|
||||||
int BuildModule();
|
|
||||||
|
|
||||||
// Returns the engine
|
|
||||||
asIScriptEngine *GetEngine();
|
|
||||||
|
|
||||||
// Returns the current module
|
|
||||||
asIScriptModule *GetModule();
|
|
||||||
|
|
||||||
// Register the callback for resolving include directive
|
|
||||||
void SetIncludeCallback(INCLUDECALLBACK_t callback, void *userParam);
|
|
||||||
|
|
||||||
// Register the callback for resolving pragma directive
|
|
||||||
void SetPragmaCallback(PRAGMACALLBACK_t callback, void *userParam);
|
|
||||||
|
|
||||||
// Add a pre-processor define for conditional compilation
|
|
||||||
void DefineWord(const char *word);
|
|
||||||
|
|
||||||
// Enumerate included script sections
|
|
||||||
unsigned int GetSectionCount() const;
|
|
||||||
std::string GetSectionName(unsigned int idx) const;
|
|
||||||
|
|
||||||
#if AS_PROCESS_METADATA == 1
|
|
||||||
// Get metadata declared for classes, interfaces, and enums
|
|
||||||
std::vector<std::string> GetMetadataForType(int typeId);
|
|
||||||
|
|
||||||
// Get metadata declared for functions
|
|
||||||
std::vector<std::string> GetMetadataForFunc(asIScriptFunction *func);
|
|
||||||
|
|
||||||
// Get metadata declared for global variables
|
|
||||||
std::vector<std::string> GetMetadataForVar(int varIdx);
|
|
||||||
|
|
||||||
// Get metadata declared for class variables
|
|
||||||
std::vector<std::string> GetMetadataForTypeProperty(int typeId, int varIdx);
|
|
||||||
|
|
||||||
// Get metadata declared for class methods
|
|
||||||
std::vector<std::string> GetMetadataForTypeMethod(int typeId, asIScriptFunction *method);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void ClearAll();
|
|
||||||
int Build();
|
|
||||||
int ProcessScriptSection(const char *script, unsigned int length, const char *sectionname, int lineOffset);
|
|
||||||
int LoadScriptSection(const char *filename);
|
|
||||||
bool IncludeIfNotAlreadyIncluded(const char *filename);
|
|
||||||
|
|
||||||
int SkipStatement(int pos);
|
|
||||||
|
|
||||||
int ExcludeCode(int start);
|
|
||||||
void OverwriteCode(int start, int len);
|
|
||||||
|
|
||||||
asIScriptEngine *engine;
|
|
||||||
asIScriptModule *module;
|
|
||||||
std::string modifiedScript;
|
|
||||||
|
|
||||||
INCLUDECALLBACK_t includeCallback;
|
|
||||||
void *includeParam;
|
|
||||||
|
|
||||||
PRAGMACALLBACK_t pragmaCallback;
|
|
||||||
void *pragmaParam;
|
|
||||||
|
|
||||||
#if AS_PROCESS_METADATA == 1
|
|
||||||
int ExtractMetadata(int pos, std::vector<std::string> &outMetadata);
|
|
||||||
int ExtractDeclaration(int pos, std::string &outName, std::string &outDeclaration, int &outType);
|
|
||||||
|
|
||||||
enum METADATATYPE
|
|
||||||
{
|
|
||||||
MDT_TYPE = 1,
|
|
||||||
MDT_FUNC = 2,
|
|
||||||
MDT_VAR = 3,
|
|
||||||
MDT_VIRTPROP = 4,
|
|
||||||
MDT_FUNC_OR_VAR = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
// Temporary structure for storing metadata and declaration
|
|
||||||
struct SMetadataDecl
|
|
||||||
{
|
|
||||||
SMetadataDecl(std::vector<std::string> m, std::string n, std::string d, int t, std::string c, std::string ns) : metadata(m), name(n), declaration(d), type(t), parentClass(c), nameSpace(ns) {}
|
|
||||||
std::vector<std::string> metadata;
|
|
||||||
std::string name;
|
|
||||||
std::string declaration;
|
|
||||||
int type;
|
|
||||||
std::string parentClass;
|
|
||||||
std::string nameSpace;
|
|
||||||
};
|
|
||||||
std::vector<SMetadataDecl> foundDeclarations;
|
|
||||||
std::string currentClass;
|
|
||||||
std::string currentNamespace;
|
|
||||||
|
|
||||||
// Storage of metadata for global declarations
|
|
||||||
std::map<int, std::vector<std::string> > typeMetadataMap;
|
|
||||||
std::map<int, std::vector<std::string> > funcMetadataMap;
|
|
||||||
std::map<int, std::vector<std::string> > varMetadataMap;
|
|
||||||
|
|
||||||
// Storage of metadata for class member declarations
|
|
||||||
struct SClassMetadata
|
|
||||||
{
|
|
||||||
SClassMetadata(const std::string& aName) : className(aName) {}
|
|
||||||
std::string className;
|
|
||||||
std::map<int, std::vector<std::string> > funcMetadataMap;
|
|
||||||
std::map<int, std::vector<std::string> > varMetadataMap;
|
|
||||||
};
|
|
||||||
std::map<int, SClassMetadata> classMetadataMap;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// On Windows the filenames are case insensitive so the comparisons to
|
|
||||||
// avoid duplicate includes must also be case insensitive. True case insensitive
|
|
||||||
// is not easy as it must be language aware, but a simple implementation such
|
|
||||||
// as strcmpi should suffice in almost all cases.
|
|
||||||
//
|
|
||||||
// ref: http://www.gotw.ca/gotw/029.htm
|
|
||||||
// ref: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317761(v=vs.85).aspx
|
|
||||||
// ref: http://site.icu-project.org/
|
|
||||||
|
|
||||||
// TODO: Strings by default are treated as UTF8 encoded. If the application choses to
|
|
||||||
// use a different encoding, the comparison algorithm should be adjusted as well
|
|
||||||
|
|
||||||
struct ci_less
|
|
||||||
{
|
|
||||||
bool operator()(const std::string &a, const std::string &b) const
|
|
||||||
{
|
|
||||||
return _stricmp(a.c_str(), b.c_str()) < 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
std::set<std::string, ci_less> includedScripts;
|
|
||||||
#else
|
|
||||||
std::set<std::string> includedScripts;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::set<std::string> definedWords;
|
|
||||||
};
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,240 +0,0 @@
|
||||||
#ifndef SCRIPTDICTIONARY_H
|
|
||||||
#define SCRIPTDICTIONARY_H
|
|
||||||
|
|
||||||
// The dictionary class relies on the script string object, thus the script
|
|
||||||
// string type must be registered with the engine before registering the
|
|
||||||
// dictionary type
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// By default the CScriptDictionary use the std::string for the keys.
|
|
||||||
// If the application uses a custom string type, then this typedef
|
|
||||||
// can be changed accordingly.
|
|
||||||
#include <string>
|
|
||||||
typedef std::string dictKey_t;
|
|
||||||
|
|
||||||
// Forward declare CScriptDictValue so we can typedef the internal map type
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
class CScriptDictValue;
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
// C++11 introduced the std::unordered_map which is a hash map which is
|
|
||||||
// is generally more performatic for lookups than the std::map which is a
|
|
||||||
// binary tree.
|
|
||||||
// TODO: memory: The map allocator should use the asAllocMem and asFreeMem
|
|
||||||
#if AS_CAN_USE_CPP11
|
|
||||||
#include <unordered_map>
|
|
||||||
typedef std::unordered_map<dictKey_t, AS_NAMESPACE_QUALIFIER CScriptDictValue> dictMap_t;
|
|
||||||
#else
|
|
||||||
#include <map>
|
|
||||||
typedef std::map<dictKey_t, AS_NAMESPACE_QUALIFIER CScriptDictValue> dictMap_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
// Turn off annoying warnings about truncated symbol names
|
|
||||||
#pragma warning (disable:4786)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Sometimes it may be desired to use the same method names as used by C++ STL.
|
|
||||||
// This may for example reduce time when converting code from script to C++ or
|
|
||||||
// back.
|
|
||||||
//
|
|
||||||
// 0 = off
|
|
||||||
// 1 = on
|
|
||||||
|
|
||||||
#ifndef AS_USE_STLNAMES
|
|
||||||
#define AS_USE_STLNAMES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
class CScriptArray;
|
|
||||||
class CScriptDictionary;
|
|
||||||
|
|
||||||
class CScriptDictValue
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// This class must not be declared as local variable in C++, because it needs
|
|
||||||
// to receive the script engine pointer in all operations. The engine pointer
|
|
||||||
// is not kept as member in order to keep the size down
|
|
||||||
CScriptDictValue();
|
|
||||||
CScriptDictValue(asIScriptEngine *engine, void *value, int typeId);
|
|
||||||
|
|
||||||
// Destructor must not be called without first calling FreeValue, otherwise a memory leak will occur
|
|
||||||
~CScriptDictValue();
|
|
||||||
|
|
||||||
// Replace the stored value
|
|
||||||
void Set(asIScriptEngine *engine, void *value, int typeId);
|
|
||||||
void Set(asIScriptEngine *engine, const asINT64 &value);
|
|
||||||
void Set(asIScriptEngine *engine, const double &value);
|
|
||||||
void Set(asIScriptEngine *engine, CScriptDictValue &value);
|
|
||||||
|
|
||||||
// Gets the stored value. Returns false if the value isn't compatible with the informed typeId
|
|
||||||
bool Get(asIScriptEngine *engine, void *value, int typeId) const;
|
|
||||||
bool Get(asIScriptEngine *engine, asINT64 &value) const;
|
|
||||||
bool Get(asIScriptEngine *engine, double &value) const;
|
|
||||||
|
|
||||||
// Returns the address of the stored value for inspection
|
|
||||||
const void *GetAddressOfValue() const;
|
|
||||||
|
|
||||||
// Returns the type id of the stored value
|
|
||||||
int GetTypeId() const;
|
|
||||||
|
|
||||||
// Free the stored value
|
|
||||||
void FreeValue(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
// GC callback
|
|
||||||
void EnumReferences(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CScriptDictionary;
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
asINT64 m_valueInt;
|
|
||||||
double m_valueFlt;
|
|
||||||
void *m_valueObj;
|
|
||||||
};
|
|
||||||
int m_typeId;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CScriptDictionary
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Factory functions
|
|
||||||
static CScriptDictionary *Create(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
// Called from the script to instantiate a dictionary from an initialization list
|
|
||||||
static CScriptDictionary *Create(asBYTE *buffer);
|
|
||||||
|
|
||||||
// Reference counting
|
|
||||||
void AddRef() const;
|
|
||||||
void Release() const;
|
|
||||||
|
|
||||||
// Reassign the dictionary
|
|
||||||
CScriptDictionary &operator =(const CScriptDictionary &other);
|
|
||||||
|
|
||||||
// Sets a key/value pair
|
|
||||||
void Set(const dictKey_t &key, void *value, int typeId);
|
|
||||||
void Set(const dictKey_t &key, const asINT64 &value);
|
|
||||||
void Set(const dictKey_t &key, const double &value);
|
|
||||||
|
|
||||||
// Gets the stored value. Returns false if the value isn't compatible with the informed typeId
|
|
||||||
bool Get(const dictKey_t &key, void *value, int typeId) const;
|
|
||||||
bool Get(const dictKey_t &key, asINT64 &value) const;
|
|
||||||
bool Get(const dictKey_t &key, double &value) const;
|
|
||||||
|
|
||||||
// Index accessors. If the dictionary is not const it inserts the value if it doesn't already exist
|
|
||||||
// If the dictionary is const then a script exception is set if it doesn't exist and a null pointer is returned
|
|
||||||
CScriptDictValue *operator[](const dictKey_t &key);
|
|
||||||
const CScriptDictValue *operator[](const dictKey_t &key) const;
|
|
||||||
|
|
||||||
// Returns the type id of the stored value, or negative if it doesn't exist
|
|
||||||
int GetTypeId(const dictKey_t &key) const;
|
|
||||||
|
|
||||||
// Returns true if the key is set
|
|
||||||
bool Exists(const dictKey_t &key) const;
|
|
||||||
|
|
||||||
// Returns true if there are no key/value pairs in the dictionary
|
|
||||||
bool IsEmpty() const;
|
|
||||||
|
|
||||||
// Returns the number of key/value pairs in the dictionary
|
|
||||||
asUINT GetSize() const;
|
|
||||||
|
|
||||||
// Deletes the key
|
|
||||||
bool Delete(const dictKey_t &key);
|
|
||||||
|
|
||||||
// Deletes all keys
|
|
||||||
void DeleteAll();
|
|
||||||
|
|
||||||
// Get an array of all keys
|
|
||||||
CScriptArray *GetKeys() const;
|
|
||||||
|
|
||||||
// STL style iterator
|
|
||||||
class CIterator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void operator++(); // Pre-increment
|
|
||||||
void operator++(int); // Post-increment
|
|
||||||
|
|
||||||
// This is needed to support C++11 range-for
|
|
||||||
CIterator &operator*();
|
|
||||||
|
|
||||||
bool operator==(const CIterator &other) const;
|
|
||||||
bool operator!=(const CIterator &other) const;
|
|
||||||
|
|
||||||
// Accessors
|
|
||||||
const dictKey_t &GetKey() const;
|
|
||||||
int GetTypeId() const;
|
|
||||||
bool GetValue(asINT64 &value) const;
|
|
||||||
bool GetValue(double &value) const;
|
|
||||||
bool GetValue(void *value, int typeId) const;
|
|
||||||
const void * GetAddressOfValue() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CScriptDictionary;
|
|
||||||
|
|
||||||
CIterator();
|
|
||||||
CIterator(const CScriptDictionary &dict,
|
|
||||||
dictMap_t::const_iterator it);
|
|
||||||
|
|
||||||
CIterator &operator=(const CIterator &) {return *this;} // Not used
|
|
||||||
|
|
||||||
dictMap_t::const_iterator m_it;
|
|
||||||
const CScriptDictionary &m_dict;
|
|
||||||
};
|
|
||||||
|
|
||||||
CIterator begin() const;
|
|
||||||
CIterator end() const;
|
|
||||||
CIterator find(const dictKey_t &key) const;
|
|
||||||
|
|
||||||
// Garbage collections behaviours
|
|
||||||
int GetRefCount();
|
|
||||||
void SetGCFlag();
|
|
||||||
bool GetGCFlag();
|
|
||||||
void EnumReferences(asIScriptEngine *engine);
|
|
||||||
void ReleaseAllReferences(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Since the dictionary uses the asAllocMem and asFreeMem functions to allocate memory
|
|
||||||
// the constructors are made protected so that the application cannot allocate it
|
|
||||||
// manually in a different way
|
|
||||||
CScriptDictionary(asIScriptEngine *engine);
|
|
||||||
CScriptDictionary(asBYTE *buffer);
|
|
||||||
|
|
||||||
// We don't want anyone to call the destructor directly, it should be called through the Release method
|
|
||||||
virtual ~CScriptDictionary();
|
|
||||||
|
|
||||||
// Cache the object types needed
|
|
||||||
void Init(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
// Our properties
|
|
||||||
asIScriptEngine *engine;
|
|
||||||
mutable int refCount;
|
|
||||||
mutable bool gcFlag;
|
|
||||||
dictMap_t dict;
|
|
||||||
};
|
|
||||||
|
|
||||||
// This function will determine the configuration of the engine
|
|
||||||
// and use one of the two functions below to register the dictionary object
|
|
||||||
void RegisterScriptDictionary(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
// Call this function to register the math functions
|
|
||||||
// using native calling conventions
|
|
||||||
void RegisterScriptDictionary_Native(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
// Use this one instead if native calling conventions
|
|
||||||
// are not supported on the target platform
|
|
||||||
void RegisterScriptDictionary_Generic(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,360 +0,0 @@
|
||||||
#include "scripthandle.h"
|
|
||||||
#include <new>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
static void Construct(CScriptHandle *self) { new(self) CScriptHandle(); }
|
|
||||||
static void Construct(CScriptHandle *self, const CScriptHandle &o) { new(self) CScriptHandle(o); }
|
|
||||||
// This one is not static because it needs to be friend with the CScriptHandle class
|
|
||||||
void Construct(CScriptHandle *self, void *ref, int typeId) { new(self) CScriptHandle(ref, typeId); }
|
|
||||||
static void Destruct(CScriptHandle *self) { self->~CScriptHandle(); }
|
|
||||||
|
|
||||||
CScriptHandle::CScriptHandle()
|
|
||||||
{
|
|
||||||
m_ref = 0;
|
|
||||||
m_type = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CScriptHandle::CScriptHandle(const CScriptHandle &other)
|
|
||||||
{
|
|
||||||
m_ref = other.m_ref;
|
|
||||||
m_type = other.m_type;
|
|
||||||
|
|
||||||
AddRefHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
CScriptHandle::CScriptHandle(void *ref, asITypeInfo *type)
|
|
||||||
{
|
|
||||||
m_ref = ref;
|
|
||||||
m_type = type;
|
|
||||||
|
|
||||||
AddRefHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This constructor shouldn't be called from the application
|
|
||||||
// directly as it requires an active script context
|
|
||||||
CScriptHandle::CScriptHandle(void *ref, int typeId)
|
|
||||||
{
|
|
||||||
m_ref = 0;
|
|
||||||
m_type = 0;
|
|
||||||
|
|
||||||
Assign(ref, typeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
CScriptHandle::~CScriptHandle()
|
|
||||||
{
|
|
||||||
ReleaseHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle::ReleaseHandle()
|
|
||||||
{
|
|
||||||
if( m_ref && m_type )
|
|
||||||
{
|
|
||||||
asIScriptEngine *engine = m_type->GetEngine();
|
|
||||||
engine->ReleaseScriptObject(m_ref, m_type);
|
|
||||||
|
|
||||||
engine->Release();
|
|
||||||
|
|
||||||
m_ref = 0;
|
|
||||||
m_type = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle::AddRefHandle()
|
|
||||||
{
|
|
||||||
if( m_ref && m_type )
|
|
||||||
{
|
|
||||||
asIScriptEngine *engine = m_type->GetEngine();
|
|
||||||
engine->AddRefScriptObject(m_ref, m_type);
|
|
||||||
|
|
||||||
// Hold on to the engine so it isn't destroyed while
|
|
||||||
// a reference to a script object is still held
|
|
||||||
engine->AddRef();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CScriptHandle &CScriptHandle::operator =(const CScriptHandle &other)
|
|
||||||
{
|
|
||||||
Set(other.m_ref, other.m_type);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle::Set(void *ref, asITypeInfo *type)
|
|
||||||
{
|
|
||||||
if( m_ref == ref ) return;
|
|
||||||
|
|
||||||
ReleaseHandle();
|
|
||||||
|
|
||||||
m_ref = ref;
|
|
||||||
m_type = type;
|
|
||||||
|
|
||||||
AddRefHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void *CScriptHandle::GetRef()
|
|
||||||
{
|
|
||||||
return m_ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
asITypeInfo *CScriptHandle::GetType() const
|
|
||||||
{
|
|
||||||
return m_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CScriptHandle::GetTypeId() const
|
|
||||||
{
|
|
||||||
if( m_type == 0 ) return 0;
|
|
||||||
|
|
||||||
return m_type->GetTypeId() | asTYPEID_OBJHANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method shouldn't be called from the application
|
|
||||||
// directly as it requires an active script context
|
|
||||||
CScriptHandle &CScriptHandle::Assign(void *ref, int typeId)
|
|
||||||
{
|
|
||||||
// When receiving a null handle we just clear our memory
|
|
||||||
if( typeId == 0 )
|
|
||||||
{
|
|
||||||
Set(0, 0);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dereference received handles to get the object
|
|
||||||
if( typeId & asTYPEID_OBJHANDLE )
|
|
||||||
{
|
|
||||||
// Store the actual reference
|
|
||||||
ref = *(void**)ref;
|
|
||||||
typeId &= ~asTYPEID_OBJHANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the object type
|
|
||||||
asIScriptContext *ctx = asGetActiveContext();
|
|
||||||
asIScriptEngine *engine = ctx->GetEngine();
|
|
||||||
asITypeInfo *type = engine->GetTypeInfoById(typeId);
|
|
||||||
|
|
||||||
// If the argument is another CScriptHandle, we should copy the content instead
|
|
||||||
if( type && strcmp(type->GetName(), "ref") == 0 )
|
|
||||||
{
|
|
||||||
CScriptHandle *r = (CScriptHandle*)ref;
|
|
||||||
ref = r->m_ref;
|
|
||||||
type = r->m_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set(ref, type);
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CScriptHandle::operator==(const CScriptHandle &o) const
|
|
||||||
{
|
|
||||||
if( m_ref == o.m_ref &&
|
|
||||||
m_type == o.m_type )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// TODO: If type is not the same, we should attempt to do a dynamic cast,
|
|
||||||
// which may change the pointer for application registered classes
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CScriptHandle::operator!=(const CScriptHandle &o) const
|
|
||||||
{
|
|
||||||
return !(*this == o);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CScriptHandle::Equals(void *ref, int typeId) const
|
|
||||||
{
|
|
||||||
// Null handles are received as reference to a null handle
|
|
||||||
if( typeId == 0 )
|
|
||||||
ref = 0;
|
|
||||||
|
|
||||||
// Dereference handles to get the object
|
|
||||||
if( typeId & asTYPEID_OBJHANDLE )
|
|
||||||
{
|
|
||||||
// Compare the actual reference
|
|
||||||
ref = *(void**)ref;
|
|
||||||
typeId &= ~asTYPEID_OBJHANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: If typeId is not the same, we should attempt to do a dynamic cast,
|
|
||||||
// which may change the pointer for application registered classes
|
|
||||||
|
|
||||||
if( ref == m_ref ) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AngelScript: used as '@obj = cast<obj>(ref);'
|
|
||||||
void CScriptHandle::Cast(void **outRef, int typeId)
|
|
||||||
{
|
|
||||||
// If we hold a null handle, then just return null
|
|
||||||
if( m_type == 0 )
|
|
||||||
{
|
|
||||||
*outRef = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is expected that the outRef is always a handle
|
|
||||||
assert( typeId & asTYPEID_OBJHANDLE );
|
|
||||||
|
|
||||||
// Compare the type id of the actual object
|
|
||||||
typeId &= ~asTYPEID_OBJHANDLE;
|
|
||||||
asIScriptEngine *engine = m_type->GetEngine();
|
|
||||||
asITypeInfo *type = engine->GetTypeInfoById(typeId);
|
|
||||||
|
|
||||||
*outRef = 0;
|
|
||||||
|
|
||||||
// RefCastObject will increment the refCount of the returned object if successful
|
|
||||||
engine->RefCastObject(m_ref, m_type, type, outRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle::EnumReferences(asIScriptEngine *inEngine)
|
|
||||||
{
|
|
||||||
// If we're holding a reference, we'll notify the garbage collector of it
|
|
||||||
if (m_ref)
|
|
||||||
inEngine->GCEnumCallback(m_ref);
|
|
||||||
|
|
||||||
// The object type itself is also garbage collected
|
|
||||||
if( m_type)
|
|
||||||
inEngine->GCEnumCallback(m_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle::ReleaseReferences(asIScriptEngine *)
|
|
||||||
{
|
|
||||||
// Simply clear the content to release the references
|
|
||||||
Set(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterScriptHandle_Native(asIScriptEngine *engine)
|
|
||||||
{
|
|
||||||
[[maybe_unused]] int r;
|
|
||||||
|
|
||||||
#if AS_CAN_USE_CPP11
|
|
||||||
// With C++11 it is possible to use asGetTypeTraits to automatically determine the flags that represent the C++ class
|
|
||||||
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_GC | asGetTypeTraits<CScriptHandle>()); assert( r >= 0 );
|
|
||||||
#else
|
|
||||||
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_GC | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
|
|
||||||
#endif
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(Construct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTIONPR(Construct, (CScriptHandle *, const CScriptHandle &), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTIONPR(Construct, (CScriptHandle *, void *, int), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTIONPR(Destruct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(CScriptHandle,EnumReferences), asCALL_THISCALL); assert(r >= 0);
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(CScriptHandle, ReleaseReferences), asCALL_THISCALL); assert(r >= 0);
|
|
||||||
r = engine->RegisterObjectMethod("ref", "void opCast(?&out)", asMETHODPR(CScriptHandle, Cast, (void **, int), void), asCALL_THISCALL); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ref &in)", asMETHOD(CScriptHandle, operator=), asCALL_THISCALL); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ?&in)", asMETHOD(CScriptHandle, Assign), asCALL_THISCALL); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asMETHODPR(CScriptHandle, operator==, (const CScriptHandle &) const, bool), asCALL_THISCALL); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asMETHODPR(CScriptHandle, Equals, (void*, int) const, bool), asCALL_THISCALL); assert( r >= 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_Construct_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
new(self) CScriptHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_ConstructCopy_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
new(self) CScriptHandle(*other);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_ConstructVar_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
void *ref = gen->GetArgAddress(0);
|
|
||||||
int typeId = gen->GetArgTypeId(0);
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
Construct(self, ref, typeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_Destruct_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
self->~CScriptHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_Cast_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
void **ref = reinterpret_cast<void**>(gen->GetArgAddress(0));
|
|
||||||
int typeId = gen->GetArgTypeId(0);
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
self->Cast(ref, typeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_Assign_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
*self = *other;
|
|
||||||
gen->SetReturnAddress(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
void *ref = gen->GetArgAddress(0);
|
|
||||||
int typeId = gen->GetArgTypeId(0);
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
self->Assign(ref, typeId);
|
|
||||||
gen->SetReturnAddress(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_Equals_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
gen->SetReturnByte(*self == *other);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_EqualsVar_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
void *ref = gen->GetArgAddress(0);
|
|
||||||
int typeId = gen->GetArgTypeId(0);
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
gen->SetReturnByte(self->Equals(ref, typeId));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_EnumReferences_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
self->EnumReferences(gen->GetEngine());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScriptHandle_ReleaseReferences_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
|
|
||||||
self->ReleaseReferences(gen->GetEngine());
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterScriptHandle_Generic(asIScriptEngine *engine)
|
|
||||||
{
|
|
||||||
[[maybe_unused]] int r;
|
|
||||||
|
|
||||||
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_GC | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(CScriptHandle_Construct_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTION(CScriptHandle_ConstructCopy_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTION(CScriptHandle_ConstructVar_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(CScriptHandle_Destruct_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(CScriptHandle_EnumReferences_Generic), asCALL_GENERIC); assert(r >= 0);
|
|
||||||
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(CScriptHandle_ReleaseReferences_Generic), asCALL_GENERIC); assert(r >= 0);
|
|
||||||
r = engine->RegisterObjectMethod("ref", "void opCast(?&out)", asFUNCTION(CScriptHandle_Cast_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ref &in)", asFUNCTION(CScriptHandle_Assign_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "ref &opHndlAssign(const ?&in)", asFUNCTION(CScriptHandle_AssignVar_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asFUNCTION(CScriptHandle_Equals_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asFUNCTION(CScriptHandle_EqualsVar_Generic), asCALL_GENERIC); assert( r >= 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterScriptHandle(asIScriptEngine *engine)
|
|
||||||
{
|
|
||||||
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
|
|
||||||
RegisterScriptHandle_Generic(engine);
|
|
||||||
else
|
|
||||||
RegisterScriptHandle_Native(engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
|
@ -1,69 +0,0 @@
|
||||||
#ifndef SCRIPTHANDLE_H
|
|
||||||
#define SCRIPTHANDLE_H
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
class CScriptHandle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
CScriptHandle();
|
|
||||||
CScriptHandle(const CScriptHandle &other);
|
|
||||||
CScriptHandle(void *ref, asITypeInfo *type);
|
|
||||||
~CScriptHandle();
|
|
||||||
|
|
||||||
// Copy the stored value from another any object
|
|
||||||
CScriptHandle &operator=(const CScriptHandle &other);
|
|
||||||
|
|
||||||
// Set the reference
|
|
||||||
void Set(void *ref, asITypeInfo *type);
|
|
||||||
|
|
||||||
// Compare equalness
|
|
||||||
bool operator==(const CScriptHandle &o) const;
|
|
||||||
bool operator!=(const CScriptHandle &o) const;
|
|
||||||
bool Equals(void *ref, int typeId) const;
|
|
||||||
|
|
||||||
// Dynamic cast to desired handle type
|
|
||||||
void Cast(void **outRef, int typeId);
|
|
||||||
|
|
||||||
// Returns the type of the reference held
|
|
||||||
asITypeInfo *GetType() const;
|
|
||||||
int GetTypeId() const;
|
|
||||||
|
|
||||||
// Get the reference
|
|
||||||
void *GetRef();
|
|
||||||
|
|
||||||
// GC callback
|
|
||||||
void EnumReferences(asIScriptEngine *engine);
|
|
||||||
void ReleaseReferences(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// These functions need to have access to protected
|
|
||||||
// members in order to call them from the script engine
|
|
||||||
friend void Construct(CScriptHandle *self, void *ref, int typeId);
|
|
||||||
friend void RegisterScriptHandle_Native(asIScriptEngine *engine);
|
|
||||||
friend void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen);
|
|
||||||
|
|
||||||
void ReleaseHandle();
|
|
||||||
void AddRefHandle();
|
|
||||||
|
|
||||||
// These shouldn't be called directly by the
|
|
||||||
// application as they requires an active context
|
|
||||||
CScriptHandle(void *ref, int typeId);
|
|
||||||
CScriptHandle &Assign(void *ref, int typeId);
|
|
||||||
|
|
||||||
void *m_ref;
|
|
||||||
asITypeInfo *m_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
void RegisterScriptHandle(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,987 +0,0 @@
|
||||||
#include <string.h>
|
|
||||||
#include "scripthelper.h"
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fstream>
|
|
||||||
#include <set>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
int CompareRelation(asIScriptEngine *engine, void *lobj, void *robj, int typeId, int &result)
|
|
||||||
{
|
|
||||||
// TODO: If a lot of script objects are going to be compared, e.g. when sorting an array,
|
|
||||||
// then the method id and context should be cached between calls.
|
|
||||||
|
|
||||||
int retval = -1;
|
|
||||||
asIScriptFunction *func = 0;
|
|
||||||
|
|
||||||
asITypeInfo *ti = engine->GetTypeInfoById(typeId);
|
|
||||||
if( ti )
|
|
||||||
{
|
|
||||||
// Check if the object type has a compatible opCmp method
|
|
||||||
for( asUINT n = 0; n < ti->GetMethodCount(); n++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *f = ti->GetMethodByIndex(n);
|
|
||||||
asDWORD flags;
|
|
||||||
if( strcmp(f->GetName(), "opCmp") == 0 &&
|
|
||||||
f->GetReturnTypeId(&flags) == asTYPEID_INT32 &&
|
|
||||||
flags == asTM_NONE &&
|
|
||||||
f->GetParamCount() == 1 )
|
|
||||||
{
|
|
||||||
int paramTypeId;
|
|
||||||
f->GetParam(0, ¶mTypeId, &flags);
|
|
||||||
|
|
||||||
// The parameter must be an input reference of the same type
|
|
||||||
// If the reference is a inout reference, then it must also be read-only
|
|
||||||
if( !(flags & asTM_INREF) || typeId != paramTypeId || ((flags & asTM_OUTREF) && !(flags & asTM_CONST)) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Found the method
|
|
||||||
func = f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( func )
|
|
||||||
{
|
|
||||||
// Call the method
|
|
||||||
asIScriptContext *ctx = engine->CreateContext();
|
|
||||||
ctx->Prepare(func);
|
|
||||||
ctx->SetObject(lobj);
|
|
||||||
ctx->SetArgAddress(0, robj);
|
|
||||||
int r = ctx->Execute();
|
|
||||||
if( r == asEXECUTION_FINISHED )
|
|
||||||
{
|
|
||||||
result = (int)ctx->GetReturnDWord();
|
|
||||||
|
|
||||||
// The comparison was successful
|
|
||||||
retval = 0;
|
|
||||||
}
|
|
||||||
ctx->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CompareEquality(asIScriptEngine *engine, void *lobj, void *robj, int typeId, bool &result)
|
|
||||||
{
|
|
||||||
// TODO: If a lot of script objects are going to be compared, e.g. when searching for an
|
|
||||||
// entry in a set, then the method and context should be cached between calls.
|
|
||||||
|
|
||||||
int retval = -1;
|
|
||||||
asIScriptFunction *func = 0;
|
|
||||||
|
|
||||||
asITypeInfo *ti = engine->GetTypeInfoById(typeId);
|
|
||||||
if( ti )
|
|
||||||
{
|
|
||||||
// Check if the object type has a compatible opEquals method
|
|
||||||
for( asUINT n = 0; n < ti->GetMethodCount(); n++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *f = ti->GetMethodByIndex(n);
|
|
||||||
asDWORD flags;
|
|
||||||
if( strcmp(f->GetName(), "opEquals") == 0 &&
|
|
||||||
f->GetReturnTypeId(&flags) == asTYPEID_BOOL &&
|
|
||||||
flags == asTM_NONE &&
|
|
||||||
f->GetParamCount() == 1 )
|
|
||||||
{
|
|
||||||
int paramTypeId;
|
|
||||||
f->GetParam(0, ¶mTypeId, &flags);
|
|
||||||
|
|
||||||
// The parameter must be an input reference of the same type
|
|
||||||
// If the reference is a inout reference, then it must also be read-only
|
|
||||||
if( !(flags & asTM_INREF) || typeId != paramTypeId || ((flags & asTM_OUTREF) && !(flags & asTM_CONST)) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Found the method
|
|
||||||
func = f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( func )
|
|
||||||
{
|
|
||||||
// Call the method
|
|
||||||
asIScriptContext *ctx = engine->CreateContext();
|
|
||||||
ctx->Prepare(func);
|
|
||||||
ctx->SetObject(lobj);
|
|
||||||
ctx->SetArgAddress(0, robj);
|
|
||||||
int r = ctx->Execute();
|
|
||||||
if( r == asEXECUTION_FINISHED )
|
|
||||||
{
|
|
||||||
result = ctx->GetReturnByte() ? true : false;
|
|
||||||
|
|
||||||
// The comparison was successful
|
|
||||||
retval = 0;
|
|
||||||
}
|
|
||||||
ctx->Release();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If the opEquals method doesn't exist, then we try with opCmp instead
|
|
||||||
int relation;
|
|
||||||
retval = CompareRelation(engine, lobj, robj, typeId, relation);
|
|
||||||
if( retval >= 0 )
|
|
||||||
result = relation == 0 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ExecuteString(asIScriptEngine *engine, const char *code, asIScriptModule *mod, asIScriptContext *ctx)
|
|
||||||
{
|
|
||||||
return ExecuteString(engine, code, 0, asTYPEID_VOID, mod, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ExecuteString(asIScriptEngine *engine, const char *code, void *ref, int refTypeId, asIScriptModule *mod, asIScriptContext *ctx)
|
|
||||||
{
|
|
||||||
// Wrap the code in a function so that it can be compiled and executed
|
|
||||||
string funcCode = " ExecuteString() {\n";
|
|
||||||
funcCode += code;
|
|
||||||
funcCode += "\n;}";
|
|
||||||
|
|
||||||
// Determine the return type based on the type of the ref arg
|
|
||||||
funcCode = engine->GetTypeDeclaration(refTypeId, true) + funcCode;
|
|
||||||
|
|
||||||
// GetModule will free unused types, so to be on the safe side we'll hold on to a reference to the type
|
|
||||||
asITypeInfo *type = 0;
|
|
||||||
if( refTypeId & asTYPEID_MASK_OBJECT )
|
|
||||||
{
|
|
||||||
type = engine->GetTypeInfoById(refTypeId);
|
|
||||||
if( type )
|
|
||||||
type->AddRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no module was provided, get a dummy from the engine
|
|
||||||
asIScriptModule *execMod = mod ? mod : engine->GetModule("ExecuteString", asGM_ALWAYS_CREATE);
|
|
||||||
|
|
||||||
// Now it's ok to release the type
|
|
||||||
if( type )
|
|
||||||
type->Release();
|
|
||||||
|
|
||||||
// Compile the function that can be executed
|
|
||||||
asIScriptFunction *func = 0;
|
|
||||||
int r = execMod->CompileFunction("ExecuteString", funcCode.c_str(), -1, 0, &func);
|
|
||||||
if( r < 0 )
|
|
||||||
return r;
|
|
||||||
|
|
||||||
// If no context was provided, request a new one from the engine
|
|
||||||
asIScriptContext *execCtx = ctx ? ctx : engine->RequestContext();
|
|
||||||
r = execCtx->Prepare(func);
|
|
||||||
if (r >= 0)
|
|
||||||
{
|
|
||||||
// Execute the function
|
|
||||||
r = execCtx->Execute();
|
|
||||||
|
|
||||||
// Unless the provided type was void retrieve it's value
|
|
||||||
if (ref != 0 && refTypeId != asTYPEID_VOID)
|
|
||||||
{
|
|
||||||
if (refTypeId & asTYPEID_OBJHANDLE)
|
|
||||||
{
|
|
||||||
// Expect the pointer to be null to start with
|
|
||||||
assert(*reinterpret_cast<void**>(ref) == 0);
|
|
||||||
*reinterpret_cast<void**>(ref) = *reinterpret_cast<void**>(execCtx->GetAddressOfReturnValue());
|
|
||||||
engine->AddRefScriptObject(*reinterpret_cast<void**>(ref), engine->GetTypeInfoById(refTypeId));
|
|
||||||
}
|
|
||||||
else if (refTypeId & asTYPEID_MASK_OBJECT)
|
|
||||||
{
|
|
||||||
// Use the registered assignment operator to do a value assign.
|
|
||||||
// This assumes that the ref is pointing to a valid object instance.
|
|
||||||
engine->AssignScriptObject(ref, execCtx->GetAddressOfReturnValue(), engine->GetTypeInfoById(refTypeId));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Copy the primitive value
|
|
||||||
memcpy(ref, execCtx->GetAddressOfReturnValue(), engine->GetSizeOfPrimitiveType(refTypeId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
func->Release();
|
|
||||||
if( !ctx ) engine->ReturnContext(execCtx);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WriteConfigToFile(asIScriptEngine *engine, const char *filename)
|
|
||||||
{
|
|
||||||
ofstream strm;
|
|
||||||
strm.open(filename);
|
|
||||||
|
|
||||||
return WriteConfigToStream(engine, strm);
|
|
||||||
}
|
|
||||||
|
|
||||||
int WriteConfigToStream(asIScriptEngine *engine, ostream &strm)
|
|
||||||
{
|
|
||||||
// A helper function for escaping quotes in default arguments
|
|
||||||
struct Escape
|
|
||||||
{
|
|
||||||
static string Quotes(const char *decl)
|
|
||||||
{
|
|
||||||
string str = decl;
|
|
||||||
size_t pos = 0;
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
// Find " characters
|
|
||||||
pos = str.find("\"",pos);
|
|
||||||
if( pos == string::npos )
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Add a \ to escape them
|
|
||||||
str.insert(pos, "\\");
|
|
||||||
pos += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int c, n;
|
|
||||||
|
|
||||||
asDWORD currAccessMask = 0;
|
|
||||||
string currNamespace = "";
|
|
||||||
engine->SetDefaultNamespace("");
|
|
||||||
|
|
||||||
// Export the engine version, just for info
|
|
||||||
strm << "// AngelScript " << asGetLibraryVersion() << "\n";
|
|
||||||
strm << "// Lib options " << asGetLibraryOptions() << "\n";
|
|
||||||
|
|
||||||
// Export the relevant engine properties
|
|
||||||
strm << "// Engine properties\n";
|
|
||||||
for( n = 0; n < asEP_LAST_PROPERTY; n++ )
|
|
||||||
strm << "ep " << n << " " << engine->GetEngineProperty(asEEngineProp(n)) << "\n";
|
|
||||||
|
|
||||||
// Make sure the default array type is expanded to the template form
|
|
||||||
bool expandDefArrayToTempl = engine->GetEngineProperty(asEP_EXPAND_DEF_ARRAY_TO_TMPL) ? true : false;
|
|
||||||
engine->SetEngineProperty(asEP_EXPAND_DEF_ARRAY_TO_TMPL, true);
|
|
||||||
|
|
||||||
// Write enum types and their values
|
|
||||||
strm << "\n// Enums\n";
|
|
||||||
c = engine->GetEnumCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asITypeInfo *ti = engine->GetEnumByIndex(n);
|
|
||||||
asDWORD accessMask = ti->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
const char *nameSpace = ti->GetNamespace();
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
const char *enumName = ti->GetName();
|
|
||||||
strm << "enum " << enumName << "\n";
|
|
||||||
for( asUINT m = 0; m < ti->GetEnumValueCount(); m++ )
|
|
||||||
{
|
|
||||||
const char *valName;
|
|
||||||
int val;
|
|
||||||
valName = ti->GetEnumValueByIndex(m, &val);
|
|
||||||
strm << "enumval " << enumName << " " << valName << " " << val << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enumerate all types
|
|
||||||
strm << "\n// Types\n";
|
|
||||||
|
|
||||||
// Keep a list of the template types, as the methods for these need to be exported first
|
|
||||||
set<asITypeInfo*> templateTypes;
|
|
||||||
|
|
||||||
c = engine->GetObjectTypeCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asITypeInfo *type = engine->GetObjectTypeByIndex(n);
|
|
||||||
asDWORD accessMask = type->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
const char *nameSpace = type->GetNamespace();
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
if( type->GetFlags() & asOBJ_SCRIPT_OBJECT )
|
|
||||||
{
|
|
||||||
// This should only be interfaces
|
|
||||||
assert( type->GetSize() == 0 );
|
|
||||||
|
|
||||||
strm << "intf " << type->GetName() << "\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Only the type flags are necessary. The application flags are application
|
|
||||||
// specific and doesn't matter to the offline compiler. The object size is also
|
|
||||||
// unnecessary for the offline compiler
|
|
||||||
strm << "objtype \"" << engine->GetTypeDeclaration(type->GetTypeId()) << "\" " << (unsigned int)(type->GetFlags() & asOBJ_MASK_VALID_FLAGS) << "\n";
|
|
||||||
|
|
||||||
// Store the template types (but not template instances)
|
|
||||||
if( (type->GetFlags() & asOBJ_TEMPLATE) && type->GetSubType() && (type->GetSubType()->GetFlags() & asOBJ_TEMPLATE_SUBTYPE) )
|
|
||||||
templateTypes.insert(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c = engine->GetTypedefCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asITypeInfo *ti = engine->GetTypedefByIndex(n);
|
|
||||||
const char *nameSpace = ti->GetNamespace();
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
asDWORD accessMask = ti->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "typedef " << ti->GetName() << " \"" << engine->GetTypeDeclaration(ti->GetTypedefTypeId()) << "\"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
c = engine->GetFuncdefCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asITypeInfo *funcDef = engine->GetFuncdefByIndex(n);
|
|
||||||
asDWORD accessMask = funcDef->GetAccessMask();
|
|
||||||
const char *nameSpace = funcDef->GetNamespace();
|
|
||||||
// Child funcdefs do not have any namespace, as they belong to the parent object
|
|
||||||
if( nameSpace && nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "funcdef \"" << funcDef->GetFuncdefSignature()->GetDeclaration() << "\"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// A helper for writing object type members
|
|
||||||
struct TypeWriter
|
|
||||||
{
|
|
||||||
static void Write(asIScriptEngine *engine, ostream &strm, asITypeInfo *type, string &currNamespace, asDWORD &currAccessMask)
|
|
||||||
{
|
|
||||||
const char *nameSpace = type->GetNamespace();
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
string typeDecl = engine->GetTypeDeclaration(type->GetTypeId());
|
|
||||||
if( type->GetFlags() & asOBJ_SCRIPT_OBJECT )
|
|
||||||
{
|
|
||||||
for( asUINT m = 0; m < type->GetMethodCount(); m++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *func = type->GetMethodByIndex(m);
|
|
||||||
asDWORD accessMask = func->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "intfmthd " << typeDecl.c_str() << " \"" << Escape::Quotes(func->GetDeclaration(false)).c_str() << (func->IsProperty() ? " property" : "") << "\"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
asUINT m;
|
|
||||||
for( m = 0; m < type->GetFactoryCount(); m++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *func = type->GetFactoryByIndex(m);
|
|
||||||
asDWORD accessMask = func->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "objbeh \"" << typeDecl.c_str() << "\" " << asBEHAVE_FACTORY << " \"" << Escape::Quotes(func->GetDeclaration(false)).c_str() << "\"\n";
|
|
||||||
}
|
|
||||||
for( m = 0; m < type->GetBehaviourCount(); m++ )
|
|
||||||
{
|
|
||||||
asEBehaviours beh;
|
|
||||||
asIScriptFunction *func = type->GetBehaviourByIndex(m, &beh);
|
|
||||||
|
|
||||||
if( beh == asBEHAVE_CONSTRUCT )
|
|
||||||
// Prefix 'void'
|
|
||||||
strm << "objbeh \"" << typeDecl.c_str() << "\" " << beh << " \"void " << Escape::Quotes(func->GetDeclaration(false)).c_str() << "\"\n";
|
|
||||||
else if( beh == asBEHAVE_DESTRUCT )
|
|
||||||
// Prefix 'void' and remove ~
|
|
||||||
strm << "objbeh \"" << typeDecl.c_str() << "\" " << beh << " \"void " << Escape::Quotes(func->GetDeclaration(false)).c_str()+1 << "\"\n";
|
|
||||||
else
|
|
||||||
strm << "objbeh \"" << typeDecl.c_str() << "\" " << beh << " \"" << Escape::Quotes(func->GetDeclaration(false)).c_str() << "\"\n";
|
|
||||||
}
|
|
||||||
for( m = 0; m < type->GetMethodCount(); m++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *func = type->GetMethodByIndex(m);
|
|
||||||
asDWORD accessMask = func->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "objmthd \"" << typeDecl.c_str() << "\" \"" << Escape::Quotes(func->GetDeclaration(false)).c_str() << (func->IsProperty() ? " property" : "") << "\"\n";
|
|
||||||
}
|
|
||||||
for( m = 0; m < type->GetPropertyCount(); m++ )
|
|
||||||
{
|
|
||||||
asDWORD accessMask;
|
|
||||||
type->GetProperty(m, 0, 0, 0, 0, 0, 0, &accessMask);
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "objprop \"" << typeDecl.c_str() << "\" \"" << type->GetPropertyDeclaration(m) << "\"";
|
|
||||||
|
|
||||||
// Save information about composite properties
|
|
||||||
int compositeOffset;
|
|
||||||
bool isCompositeIndirect;
|
|
||||||
type->GetProperty(m, 0, 0, 0, 0, 0, 0, 0, &compositeOffset, &isCompositeIndirect);
|
|
||||||
strm << " " << compositeOffset << " " << (isCompositeIndirect ? "1" : "0") << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Write the members of the template types, so they can be fully registered before any other type uses them
|
|
||||||
// TODO: Order the template types based on dependency to avoid failure if one type uses instances of another
|
|
||||||
strm << "\n// Template type members\n";
|
|
||||||
for( set<asITypeInfo*>::iterator it = templateTypes.begin(); it != templateTypes.end(); ++it )
|
|
||||||
{
|
|
||||||
asITypeInfo *type = *it;
|
|
||||||
TypeWriter::Write(engine, strm, type, currNamespace, currAccessMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the object types members
|
|
||||||
strm << "\n// Type members\n";
|
|
||||||
|
|
||||||
c = engine->GetObjectTypeCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asITypeInfo *type = engine->GetObjectTypeByIndex(n);
|
|
||||||
if( templateTypes.find(type) == templateTypes.end() )
|
|
||||||
TypeWriter::Write(engine, strm, type, currNamespace, currAccessMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write functions
|
|
||||||
strm << "\n// Functions\n";
|
|
||||||
|
|
||||||
c = engine->GetGlobalFunctionCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
asIScriptFunction *func = engine->GetGlobalFunctionByIndex(n);
|
|
||||||
const char *nameSpace = func->GetNamespace();
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
asDWORD accessMask = func->GetAccessMask();
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
strm << "func \"" << Escape::Quotes(func->GetDeclaration()).c_str() << (func->IsProperty() ? " property" : "") << "\"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write global properties
|
|
||||||
strm << "\n// Properties\n";
|
|
||||||
|
|
||||||
c = engine->GetGlobalPropertyCount();
|
|
||||||
for( n = 0; n < c; n++ )
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
int typeId;
|
|
||||||
bool isConst;
|
|
||||||
asDWORD accessMask;
|
|
||||||
const char *nameSpace;
|
|
||||||
engine->GetGlobalPropertyByIndex(n, &name, &nameSpace, &typeId, &isConst, 0, 0, &accessMask);
|
|
||||||
if( accessMask != currAccessMask )
|
|
||||||
{
|
|
||||||
strm << "access " << hex << (unsigned int)(accessMask) << dec << "\n";
|
|
||||||
currAccessMask = accessMask;
|
|
||||||
}
|
|
||||||
if( nameSpace != currNamespace )
|
|
||||||
{
|
|
||||||
strm << "namespace \"" << nameSpace << "\"\n";
|
|
||||||
currNamespace = nameSpace;
|
|
||||||
engine->SetDefaultNamespace(currNamespace.c_str());
|
|
||||||
}
|
|
||||||
strm << "prop \"" << (isConst ? "const " : "") << engine->GetTypeDeclaration(typeId) << " " << name << "\"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write string factory
|
|
||||||
strm << "\n// String factory\n";
|
|
||||||
|
|
||||||
// Reset the namespace for the string factory and default array type
|
|
||||||
if ("" != currNamespace)
|
|
||||||
{
|
|
||||||
strm << "namespace \"\"\n";
|
|
||||||
currNamespace = "";
|
|
||||||
engine->SetDefaultNamespace("");
|
|
||||||
}
|
|
||||||
|
|
||||||
asDWORD flags = 0;
|
|
||||||
int typeId = engine->GetStringFactoryReturnTypeId(&flags);
|
|
||||||
if( typeId > 0 )
|
|
||||||
strm << "strfactory \"" << ((flags & asTM_CONST) ? "const " : "") << engine->GetTypeDeclaration(typeId) << ((flags & asTM_INOUTREF) ? "&" : "") << "\"\n";
|
|
||||||
|
|
||||||
// Write default array type
|
|
||||||
strm << "\n// Default array type\n";
|
|
||||||
typeId = engine->GetDefaultArrayTypeId();
|
|
||||||
if( typeId > 0 )
|
|
||||||
strm << "defarray \"" << engine->GetTypeDeclaration(typeId) << "\"\n";
|
|
||||||
|
|
||||||
// Restore original settings
|
|
||||||
engine->SetEngineProperty(asEP_EXPAND_DEF_ARRAY_TO_TMPL, expandDefArrayToTempl);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ConfigEngineFromStream(asIScriptEngine *engine, istream &strm, const char *configFile, asIStringFactory *stringFactory)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
|
|
||||||
// Some helper functions for parsing the configuration
|
|
||||||
struct in
|
|
||||||
{
|
|
||||||
static asETokenClass GetToken(asIScriptEngine *engine, string &token, const string &text, asUINT &pos)
|
|
||||||
{
|
|
||||||
asUINT len = 0;
|
|
||||||
asETokenClass t = engine->ParseToken(&text[pos], text.length() - pos, &len);
|
|
||||||
while( (t == asTC_WHITESPACE || t == asTC_COMMENT) && pos < text.length() )
|
|
||||||
{
|
|
||||||
pos += len;
|
|
||||||
t = engine->ParseToken(&text[pos], text.length() - pos, &len);
|
|
||||||
}
|
|
||||||
|
|
||||||
token.assign(&text[pos], len);
|
|
||||||
|
|
||||||
pos += len;
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ReplaceSlashQuote(string &str)
|
|
||||||
{
|
|
||||||
size_t pos = 0;
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
// Search for \" in the string
|
|
||||||
pos = str.find("\\\"", pos);
|
|
||||||
if( pos == string::npos )
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Remove the \ character
|
|
||||||
str.erase(pos, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static asUINT GetLineNumber(const string &text, asUINT pos)
|
|
||||||
{
|
|
||||||
asUINT count = 1;
|
|
||||||
for( asUINT n = 0; n < pos; n++ )
|
|
||||||
if( text[n] == '\n' )
|
|
||||||
count++;
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Since we are only going to compile the script and never actually execute it,
|
|
||||||
// we turn off the initialization of global variables, so that the compiler can
|
|
||||||
// just register dummy types and functions for the application interface.
|
|
||||||
r = engine->SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, false); assert( r >= 0 );
|
|
||||||
|
|
||||||
// Read the entire file
|
|
||||||
char buffer[1000];
|
|
||||||
string config;
|
|
||||||
do {
|
|
||||||
strm.getline(buffer, 1000);
|
|
||||||
config += buffer;
|
|
||||||
config += "\n";
|
|
||||||
} while( !strm.eof() && strm.good() );
|
|
||||||
|
|
||||||
// Process the configuration file and register each entity
|
|
||||||
asUINT pos = 0;
|
|
||||||
while( pos < config.length() )
|
|
||||||
{
|
|
||||||
string token;
|
|
||||||
// TODO: The position where the initial token is found should be stored for error messages
|
|
||||||
in::GetToken(engine, token, config, pos);
|
|
||||||
if( token == "ep" )
|
|
||||||
{
|
|
||||||
string tmp;
|
|
||||||
in::GetToken(engine, tmp, config, pos);
|
|
||||||
|
|
||||||
asEEngineProp ep = asEEngineProp(atol(tmp.c_str()));
|
|
||||||
|
|
||||||
// Only set properties that affect the compiler
|
|
||||||
if( ep != asEP_COPY_SCRIPT_SECTIONS &&
|
|
||||||
ep != asEP_MAX_STACK_SIZE &&
|
|
||||||
ep != asEP_INIT_GLOBAL_VARS_AFTER_BUILD &&
|
|
||||||
ep != asEP_EXPAND_DEF_ARRAY_TO_TMPL &&
|
|
||||||
ep != asEP_AUTO_GARBAGE_COLLECT )
|
|
||||||
{
|
|
||||||
// Get the value for the property
|
|
||||||
in::GetToken(engine, tmp, config, pos);
|
|
||||||
stringstream s(tmp);
|
|
||||||
asPWORD value;
|
|
||||||
|
|
||||||
s >> value;
|
|
||||||
|
|
||||||
engine->SetEngineProperty(ep, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "namespace" )
|
|
||||||
{
|
|
||||||
string ns;
|
|
||||||
in::GetToken(engine, ns, config, pos);
|
|
||||||
ns = ns.substr(1, ns.length() - 2);
|
|
||||||
|
|
||||||
r = engine->SetDefaultNamespace(ns.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to set namespace");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "access" )
|
|
||||||
{
|
|
||||||
string maskStr;
|
|
||||||
in::GetToken(engine, maskStr, config, pos);
|
|
||||||
asDWORD mask = strtoul(maskStr.c_str(), 0, 16);
|
|
||||||
engine->SetDefaultAccessMask(mask);
|
|
||||||
}
|
|
||||||
else if( token == "objtype" )
|
|
||||||
{
|
|
||||||
string name, flags;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
name = name.substr(1, name.length() - 2);
|
|
||||||
in::GetToken(engine, flags, config, pos);
|
|
||||||
|
|
||||||
// The size of the value type doesn't matter, because the
|
|
||||||
// engine must adjust it anyway for different platforms
|
|
||||||
r = engine->RegisterObjectType(name.c_str(), (atol(flags.c_str()) & asOBJ_VALUE) ? 1 : 0, atol(flags.c_str()));
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register object type");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "objbeh" )
|
|
||||||
{
|
|
||||||
string name, behaviour, decl;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
name = name.substr(1, name.length() - 2);
|
|
||||||
in::GetToken(engine, behaviour, config, pos);
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
in::ReplaceSlashQuote(decl);
|
|
||||||
|
|
||||||
// Remove the $ that the engine prefixes the behaviours with
|
|
||||||
size_t n = decl.find("$");
|
|
||||||
if( n != string::npos )
|
|
||||||
decl[n] = ' ';
|
|
||||||
|
|
||||||
asEBehaviours behave = static_cast<asEBehaviours>(atol(behaviour.c_str()));
|
|
||||||
if( behave == asBEHAVE_TEMPLATE_CALLBACK )
|
|
||||||
{
|
|
||||||
// TODO: How can we let the compiler register this? Maybe through a plug-in system? Or maybe by implementing the callback as a script itself
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_WARNING, "Cannot register template callback without the actual implementation");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = engine->RegisterObjectBehaviour(name.c_str(), behave, decl.c_str(), asFUNCTION(0), asCALL_GENERIC);
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register behaviour");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "objmthd" )
|
|
||||||
{
|
|
||||||
string name, decl;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
name = name.substr(1, name.length() - 2);
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
in::ReplaceSlashQuote(decl);
|
|
||||||
|
|
||||||
r = engine->RegisterObjectMethod(name.c_str(), decl.c_str(), asFUNCTION(0), asCALL_GENERIC);
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register object method");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "objprop" )
|
|
||||||
{
|
|
||||||
string name, decl, compositeOffset, isCompositeIndirect;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
name = name.substr(1, name.length() - 2);
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
in::GetToken(engine, compositeOffset, config, pos);
|
|
||||||
in::GetToken(engine, isCompositeIndirect, config, pos);
|
|
||||||
|
|
||||||
asITypeInfo *type = engine->GetTypeInfoById(engine->GetTypeIdByDecl(name.c_str()));
|
|
||||||
if( type == 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Type doesn't exist for property registration");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All properties must have different offsets in order to make them
|
|
||||||
// distinct, so we simply register them with an incremental offset
|
|
||||||
r = engine->RegisterObjectProperty(name.c_str(), decl.c_str(), type->GetPropertyCount(), compositeOffset != "0" ? type->GetPropertyCount() : 0, isCompositeIndirect != "0");
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register object property");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "intf" )
|
|
||||||
{
|
|
||||||
string name, size, flags;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
|
|
||||||
r = engine->RegisterInterface(name.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register interface");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "intfmthd" )
|
|
||||||
{
|
|
||||||
string name, decl;
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
in::ReplaceSlashQuote(decl);
|
|
||||||
|
|
||||||
r = engine->RegisterInterfaceMethod(name.c_str(), decl.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register interface method");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "func" )
|
|
||||||
{
|
|
||||||
string decl;
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
in::ReplaceSlashQuote(decl);
|
|
||||||
|
|
||||||
r = engine->RegisterGlobalFunction(decl.c_str(), asFUNCTION(0), asCALL_GENERIC);
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register global function");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "prop" )
|
|
||||||
{
|
|
||||||
string decl;
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
|
|
||||||
// All properties must have different offsets in order to make them
|
|
||||||
// distinct, so we simply register them with an incremental offset.
|
|
||||||
// The pointer must also be non-null so we add 1 to have a value.
|
|
||||||
r = engine->RegisterGlobalProperty(decl.c_str(), reinterpret_cast<void*>(asPWORD(engine->GetGlobalPropertyCount()+1)));
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register global property");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "strfactory" )
|
|
||||||
{
|
|
||||||
string type;
|
|
||||||
in::GetToken(engine, type, config, pos);
|
|
||||||
type = type.substr(1, type.length() - 2);
|
|
||||||
|
|
||||||
if (stringFactory == 0)
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_WARNING, "Cannot register string factory without the actual implementation");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = engine->RegisterStringFactory(type.c_str(), stringFactory);
|
|
||||||
if (r < 0)
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register string factory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "defarray" )
|
|
||||||
{
|
|
||||||
string type;
|
|
||||||
in::GetToken(engine, type, config, pos);
|
|
||||||
type = type.substr(1, type.length() - 2);
|
|
||||||
|
|
||||||
r = engine->RegisterDefaultArrayType(type.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register the default array type");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "enum" )
|
|
||||||
{
|
|
||||||
string type;
|
|
||||||
in::GetToken(engine, type, config, pos);
|
|
||||||
|
|
||||||
r = engine->RegisterEnum(type.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register enum type");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "enumval" )
|
|
||||||
{
|
|
||||||
string type, name, value;
|
|
||||||
in::GetToken(engine, type, config, pos);
|
|
||||||
in::GetToken(engine, name, config, pos);
|
|
||||||
in::GetToken(engine, value, config, pos);
|
|
||||||
|
|
||||||
r = engine->RegisterEnumValue(type.c_str(), name.c_str(), atol(value.c_str()));
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register enum value");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "typedef" )
|
|
||||||
{
|
|
||||||
string type, decl;
|
|
||||||
in::GetToken(engine, type, config, pos);
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
|
|
||||||
r = engine->RegisterTypedef(type.c_str(), decl.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register typedef");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( token == "funcdef" )
|
|
||||||
{
|
|
||||||
string decl;
|
|
||||||
in::GetToken(engine, decl, config, pos);
|
|
||||||
decl = decl.substr(1, decl.length() - 2);
|
|
||||||
|
|
||||||
r = engine->RegisterFuncdef(decl.c_str());
|
|
||||||
if( r < 0 )
|
|
||||||
{
|
|
||||||
engine->WriteMessage(configFile, in::GetLineNumber(config, pos), 0, asMSGTYPE_ERROR, "Failed to register funcdef");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
string GetExceptionInfo(asIScriptContext *ctx, bool showStack)
|
|
||||||
{
|
|
||||||
if( ctx->GetState() != asEXECUTION_EXCEPTION ) return "";
|
|
||||||
|
|
||||||
stringstream text;
|
|
||||||
|
|
||||||
const asIScriptFunction *function = ctx->GetExceptionFunction();
|
|
||||||
text << "func: " << function->GetDeclaration() << "\n";
|
|
||||||
text << "modl: " << (function->GetModuleName() ? function->GetModuleName() : "") << "\n";
|
|
||||||
text << "sect: " << (function->GetScriptSectionName() ? function->GetScriptSectionName() : "") << "\n";
|
|
||||||
text << "line: " << ctx->GetExceptionLineNumber() << "\n";
|
|
||||||
text << "desc: " << ctx->GetExceptionString() << "\n";
|
|
||||||
|
|
||||||
if( showStack )
|
|
||||||
{
|
|
||||||
text << "--- call stack ---\n";
|
|
||||||
for( asUINT n = 1; n < ctx->GetCallstackSize(); n++ )
|
|
||||||
{
|
|
||||||
function = ctx->GetFunction(n);
|
|
||||||
if( function )
|
|
||||||
{
|
|
||||||
if( function->GetFuncType() == asFUNC_SCRIPT )
|
|
||||||
{
|
|
||||||
text << (function->GetScriptSectionName() ? function->GetScriptSectionName() : "") << " (" << ctx->GetLineNumber(n) << "): " << function->GetDeclaration() << "\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The context is being reused by the application for a nested call
|
|
||||||
text << "{...application...}: " << function->GetDeclaration() << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The context is being reused by the script engine for a nested call
|
|
||||||
text << "{...script engine...}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return text.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptThrow(const string &msg)
|
|
||||||
{
|
|
||||||
asIScriptContext *ctx = asGetActiveContext();
|
|
||||||
if (ctx)
|
|
||||||
ctx->SetException(msg.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
string ScriptGetExceptionInfo()
|
|
||||||
{
|
|
||||||
asIScriptContext *ctx = asGetActiveContext();
|
|
||||||
if (!ctx)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
const char *msg = ctx->GetExceptionString();
|
|
||||||
if (msg == 0)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return string(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterExceptionRoutines(asIScriptEngine *engine)
|
|
||||||
{
|
|
||||||
[[maybe_unused]] int r;
|
|
||||||
|
|
||||||
// The string type must be available
|
|
||||||
assert(engine->GetTypeInfoByDecl("string"));
|
|
||||||
|
|
||||||
r = engine->RegisterGlobalFunction("void throw(const string &in)", asFUNCTION(ScriptThrow), asCALL_CDECL); assert(r >= 0);
|
|
||||||
r = engine->RegisterGlobalFunction("string getExceptionInfo()", asFUNCTION(ScriptGetExceptionInfo), asCALL_CDECL); assert(r >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
|
@ -1,53 +0,0 @@
|
||||||
#ifndef SCRIPTHELPER_H
|
|
||||||
#define SCRIPTHELPER_H
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
// Compare relation between two objects of the same type
|
|
||||||
int CompareRelation(asIScriptEngine *engine, void *lobj, void *robj, int typeId, int &result);
|
|
||||||
|
|
||||||
// Compare equality between two objects of the same type
|
|
||||||
int CompareEquality(asIScriptEngine *engine, void *lobj, void *robj, int typeId, bool &result);
|
|
||||||
|
|
||||||
// Compile and execute simple statements
|
|
||||||
// The module is optional. If given the statements can access the entities compiled in the module.
|
|
||||||
// The caller can optionally provide its own context, for example if a context should be reused.
|
|
||||||
int ExecuteString(asIScriptEngine *engine, const char *code, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
|
|
||||||
|
|
||||||
// Compile and execute simple statements with option of return value
|
|
||||||
// The module is optional. If given the statements can access the entitites compiled in the module.
|
|
||||||
// The caller can optionally provide its own context, for example if a context should be reused.
|
|
||||||
int ExecuteString(asIScriptEngine *engine, const char *code, void *ret, int retTypeId, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
|
|
||||||
|
|
||||||
// Write the registered application interface to a file for an offline compiler.
|
|
||||||
// The format is compatible with the offline compiler in /sdk/samples/asbuild/.
|
|
||||||
int WriteConfigToFile(asIScriptEngine *engine, const char *filename);
|
|
||||||
|
|
||||||
// Write the registered application interface to a text stream.
|
|
||||||
int WriteConfigToStream(asIScriptEngine *engine, std::ostream &strm);
|
|
||||||
|
|
||||||
// Loads an interface from a text stream and configures the engine with it. This will not
|
|
||||||
// set the correct function pointers, so it is not possible to use this engine to execute
|
|
||||||
// scripts, but it can be used to compile scripts and save the byte code.
|
|
||||||
int ConfigEngineFromStream(asIScriptEngine *engine, std::istream &strm, const char *nameOfStream = "config", asIStringFactory *stringFactory = 0);
|
|
||||||
|
|
||||||
// Format the details of the script exception into a human readable text
|
|
||||||
std::string GetExceptionInfo(asIScriptContext *ctx, bool showStack = false);
|
|
||||||
|
|
||||||
// Register the exception routines
|
|
||||||
// 'void throw(const string &msg)'
|
|
||||||
// 'string getExceptionInfo()'
|
|
||||||
void RegisterExceptionRoutines(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,48 +0,0 @@
|
||||||
//
|
|
||||||
// Script std::string
|
|
||||||
//
|
|
||||||
// This function registers the std::string type with AngelScript to be used as the default string type.
|
|
||||||
//
|
|
||||||
// The string type is registered as a value type, thus may have performance issues if a lot of
|
|
||||||
// string operations are performed in the script. However, for relatively few operations, this should
|
|
||||||
// not cause any problem for most applications.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SCRIPTSTDSTRING_H
|
|
||||||
#define SCRIPTSTDSTRING_H
|
|
||||||
|
|
||||||
#ifndef ANGELSCRIPT_H
|
|
||||||
// Avoid having to inform include path if header is already include before
|
|
||||||
#include <angelscript.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
//---------------------------
|
|
||||||
// Compilation settings
|
|
||||||
//
|
|
||||||
|
|
||||||
// Sometimes it may be desired to use the same method names as used by C++ STL.
|
|
||||||
// This may for example reduce time when converting code from script to C++ or
|
|
||||||
// back.
|
|
||||||
//
|
|
||||||
// 0 = off
|
|
||||||
// 1 = on
|
|
||||||
#ifndef AS_USE_STLNAMES
|
|
||||||
#define AS_USE_STLNAMES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Some prefer to use property accessors to get/set the length of the string
|
|
||||||
// This option registers the accessors instead of the method length()
|
|
||||||
#ifndef AS_USE_ACCESSORS
|
|
||||||
#define AS_USE_ACCESSORS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
void RegisterStdString(asIScriptEngine *engine);
|
|
||||||
void RegisterStdStringUtils(asIScriptEngine *engine);
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,129 +0,0 @@
|
||||||
#include <assert.h>
|
|
||||||
#include "scriptstdstring.h"
|
|
||||||
#include "../scriptarray/scriptarray.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
BEGIN_AS_NAMESPACE
|
|
||||||
|
|
||||||
// This function takes an input string and splits it into parts by looking
|
|
||||||
// for a specified delimiter. Example:
|
|
||||||
//
|
|
||||||
// string str = "A|B||D";
|
|
||||||
// array<string>@ array = str.split("|");
|
|
||||||
//
|
|
||||||
// The resulting array has the following elements:
|
|
||||||
//
|
|
||||||
// {"A", "B", "", "D"}
|
|
||||||
//
|
|
||||||
// AngelScript signature:
|
|
||||||
// array<string>@ string::split(const string &in delim) const
|
|
||||||
static CScriptArray *StringSplit(const string &delim, const string &str)
|
|
||||||
{
|
|
||||||
// Obtain a pointer to the engine
|
|
||||||
asIScriptContext *ctx = asGetActiveContext();
|
|
||||||
asIScriptEngine *engine = ctx->GetEngine();
|
|
||||||
|
|
||||||
// TODO: This should only be done once
|
|
||||||
// TODO: This assumes that CScriptArray was already registered
|
|
||||||
asITypeInfo *arrayType = engine->GetTypeInfoByDecl("array<string>");
|
|
||||||
|
|
||||||
// Create the array object
|
|
||||||
CScriptArray *array = CScriptArray::Create(arrayType);
|
|
||||||
|
|
||||||
// Find the existence of the delimiter in the input string
|
|
||||||
int pos = 0, prev = 0, count = 0;
|
|
||||||
while( (pos = (int)str.find(delim, prev)) != (int)string::npos )
|
|
||||||
{
|
|
||||||
// Add the part to the array
|
|
||||||
array->Resize(array->GetSize()+1);
|
|
||||||
((string*)array->At(count))->assign(&str[prev], pos-prev);
|
|
||||||
|
|
||||||
// Find the next part
|
|
||||||
count++;
|
|
||||||
prev = pos + (int)delim.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the remaining part
|
|
||||||
array->Resize(array->GetSize()+1);
|
|
||||||
((string*)array->At(count))->assign(&str[prev]);
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void StringSplit_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
// Get the arguments
|
|
||||||
string *str = (string*)gen->GetObject();
|
|
||||||
string *delim = *(string**)gen->GetAddressOfArg(0);
|
|
||||||
|
|
||||||
// Return the array by handle
|
|
||||||
*(CScriptArray**)gen->GetAddressOfReturnLocation() = StringSplit(*delim, *str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This function takes as input an array of string handles as well as a
|
|
||||||
// delimiter and concatenates the array elements into one delimited string.
|
|
||||||
// Example:
|
|
||||||
//
|
|
||||||
// array<string> array = {"A", "B", "", "D"};
|
|
||||||
// string str = join(array, "|");
|
|
||||||
//
|
|
||||||
// The resulting string is:
|
|
||||||
//
|
|
||||||
// "A|B||D"
|
|
||||||
//
|
|
||||||
// AngelScript signature:
|
|
||||||
// string join(const array<string> &in array, const string &in delim)
|
|
||||||
static string StringJoin(const CScriptArray &array, const string &delim)
|
|
||||||
{
|
|
||||||
// Create the new string
|
|
||||||
string str = "";
|
|
||||||
if( array.GetSize() )
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
for( n = 0; n < (int)array.GetSize() - 1; n++ )
|
|
||||||
{
|
|
||||||
str += *(string*)array.At(n);
|
|
||||||
str += delim;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the last part
|
|
||||||
str += *(string*)array.At(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void StringJoin_Generic(asIScriptGeneric *gen)
|
|
||||||
{
|
|
||||||
// Get the arguments
|
|
||||||
CScriptArray *array = *(CScriptArray**)gen->GetAddressOfArg(0);
|
|
||||||
string *delim = *(string**)gen->GetAddressOfArg(1);
|
|
||||||
|
|
||||||
// Return the string
|
|
||||||
new(gen->GetAddressOfReturnLocation()) string(StringJoin(*array, *delim));
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is where the utility functions are registered.
|
|
||||||
// The string type must have been registered first.
|
|
||||||
void RegisterStdStringUtils(asIScriptEngine *engine)
|
|
||||||
{
|
|
||||||
[[maybe_unused]] int r;
|
|
||||||
|
|
||||||
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
|
|
||||||
{
|
|
||||||
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit_Generic), asCALL_GENERIC); assert(r >= 0);
|
|
||||||
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin_Generic), asCALL_GENERIC); assert(r >= 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
|
||||||
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin), asCALL_CDECL); assert(r >= 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
END_AS_NAMESPACE
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
||||||
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
||||||
|
|
||||||
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
||||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include <scriptarray/scriptarray.h>
|
||||||
#include "TypeRegistry/NativeArray.hpp"
|
#include "TypeRegistry/NativeArray.hpp"
|
||||||
|
|
||||||
class AngelScriptResolver;
|
class AngelScriptResolver;
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#include <CreatureLib/Battling/Models/Creature.hpp>
|
#include <CreatureLib/Battling/Models/Creature.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include "../../../extern/angelscript_addons/scriptdictionary/scriptdictionary.h"
|
#include <scriptdictionary/scriptdictionary.h>
|
||||||
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include <scripthandle/scripthandle.h>
|
||||||
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
#include <scripthelper/scripthelper.h>
|
||||||
#include "../../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
#include <scriptstdstring/scriptstdstring.h>
|
||||||
#include "../../Battling/PkmnScriptCategory.hpp"
|
#include "../../Battling/PkmnScriptCategory.hpp"
|
||||||
#include "../../Battling/Pokemon/Pokemon.hpp"
|
#include "../../Battling/Pokemon/Pokemon.hpp"
|
||||||
#include "AngelScriptMetadata.hpp"
|
#include "AngelScriptMetadata.hpp"
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include <CreatureLib/Battling/ScriptHandling/ScriptResolver.hpp>
|
#include <CreatureLib/Battling/ScriptHandling/ScriptResolver.hpp>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#ifdef ANGELSCRIPT_DEBUGGER
|
#ifdef ANGELSCRIPT_DEBUGGER
|
||||||
#include "../../../extern/AngelscriptDebuggerServer/src/AngelscriptDebugger.hpp"
|
#include <AngelscriptDebuggerServer/AngelscriptDebugger.hpp>
|
||||||
#endif
|
#endif
|
||||||
#include "../../../extern/angelscript_addons/scriptbuilder/scriptbuilder.h"
|
#include <scriptbuilder/scriptbuilder.h>
|
||||||
#include "../../Battling/Library/BattleLibrary.hpp"
|
#include "../../Battling/Library/BattleLibrary.hpp"
|
||||||
#include "AngelScriptEvolutionScript.hpp"
|
#include "AngelScriptEvolutionScript.hpp"
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
|
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
|
||||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||||
#include <angelscript.h>
|
#include <angelscript.h>
|
||||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include <scriptarray/scriptarray.h>
|
||||||
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include <scripthandle/scripthandle.h>
|
||||||
#include "../../Battling/PkmnScript.hpp"
|
#include "../../Battling/PkmnScript.hpp"
|
||||||
#include "AngelScriptTypeInfo.hpp"
|
#include "AngelScriptTypeInfo.hpp"
|
||||||
#include "TypeRegistry/NativeArray.hpp"
|
#include "TypeRegistry/NativeArray.hpp"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
#include <CreatureLib/Battling/Models/Battle.hpp>
|
||||||
#include <CreatureLib/Battling/Models/BattleSide.hpp>
|
#include <CreatureLib/Battling/Models/BattleSide.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include <scripthandle/scripthandle.h>
|
||||||
#include "../../../../Battling/Battle/Battle.hpp"
|
#include "../../../../Battling/Battle/Battle.hpp"
|
||||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||||
#include "../../AngelScriptResolver.hpp"
|
#include "../../AngelScriptResolver.hpp"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "RegisterPokemonClass.hpp"
|
#include "RegisterPokemonClass.hpp"
|
||||||
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
||||||
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include <scriptarray/scriptarray.h>
|
||||||
#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include <scripthandle/scripthandle.h>
|
||||||
#include "../../../../Battling/PkmnDamageSource.hpp"
|
#include "../../../../Battling/PkmnDamageSource.hpp"
|
||||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||||
#include "../../AngelScriptResolver.hpp"
|
#include "../../AngelScriptResolver.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Library/DamageLibrary.hpp"
|
#include "../../src/Battling/Library/DamageLibrary.hpp"
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Library/Natures/NatureLibrary.hpp"
|
#include "../../src/Library/Natures/NatureLibrary.hpp"
|
||||||
#include "../../src/Library/Statistic.hpp"
|
#include "../../src/Library/Statistic.hpp"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Library/Species/SpeciesLibrary.hpp"
|
#include "../../src/Library/Species/SpeciesLibrary.hpp"
|
||||||
|
|
||||||
TEST_CASE("Able to build and destroy empty library") {
|
TEST_CASE("Able to build and destroy empty library") {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Library/Species/PokemonSpecies.hpp"
|
#include "../../src/Library/Species/PokemonSpecies.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
|
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
|
||||||
#include <CreatureLib/Battling/TurnChoices/PassTurnChoice.hpp>
|
#include <CreatureLib/Battling/TurnChoices/PassTurnChoice.hpp>
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Battle/Battle.hpp"
|
#include "../../src/Battling/Battle/Battle.hpp"
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../src/Battling/Pokemon/PokemonParty.hpp"
|
#include "../../src/Battling/Pokemon/PokemonParty.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Library/ExperienceLibrary.hpp"
|
#include "../../src/Battling/Library/ExperienceLibrary.hpp"
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include <Arbutils/StringView.hpp>
|
#include <Arbutils/StringView.hpp>
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptMetadata.hpp"
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptMetadata.hpp"
|
||||||
|
|
||||||
TEST_CASE("Metadata without parameters") {
|
TEST_CASE("Metadata without parameters") {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../TestLibrary/TestLibrary.hpp"
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/Battling/Battle/Battle.hpp"
|
#include "../../../../src/Battling/Battle/Battle.hpp"
|
||||||
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/doctest.hpp"
|
#include <doctest.h>
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
#include "../../../../src/ScriptResolving/AngelScript/ContextPool.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
Loading…
Reference in New Issue