The origin of this software must not be misrepresented; you
18 | must not claim that you wrote the original software. If you use
19 | this software in a product, an acknowledgment in the product
20 | documentation would be appreciated but is not required.
21 |
22 |
Altered source versions must be plainly marked as such, and
23 | must not be misrepresented as being the original software.
24 |
25 |
This notice may not be removed or altered from any source
26 | distribution.
27 |
28 |
29 |
30 |
31 |
32 | */
33 |
--------------------------------------------------------------------------------
/sdk/samples/console/projects/gnuc/makefile:
--------------------------------------------------------------------------------
1 | # Tutoral GCC Makefile
2 |
3 | CXX = g++
4 | CXXFLAGS = -std=c++11 -ggdb -I../../../../angelscript/include
5 | SRCDIR = ../../source
6 | OBJDIR = obj
7 |
8 | SRCNAMES = \
9 | main.cpp
10 |
11 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) obj/scriptarray.o obj/scriptstdstring.o obj/scripthelper.o
12 | BIN = ../../bin/console
13 | DELETER = rm -f
14 |
15 | all: $(BIN)
16 |
17 | $(BIN): $(OBJ)
18 | $(CXX) -o $(BIN) $(OBJ) -static -langelscript -dynamic -lpthread -L ../../../../angelscript/lib
19 | @echo -------------------------------------------------------------------
20 | @echo Done.
21 |
22 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
23 | $(CXX) $(CXXFLAGS) -o $@ -c $<
24 |
25 | obj/scriptarray.o: ../../../../add_on/scriptarray/scriptarray.cpp
26 | $(CXX) $(CXXFLAGS) -o $@ -c $<
27 |
28 | obj/scriptstdstring.o: ../../../../add_on/scriptstdstring/scriptstdstring.cpp
29 | $(CXX) $(CXXFLAGS) -o $@ -c $<
30 |
31 | obj/scripthelper.o: ../../../../add_on/scripthelper/scripthelper.cpp
32 | $(CXX) $(CXXFLAGS) -o $@ -c $<
33 |
34 | clean:
35 | $(DELETER) $(OBJ) $(BIN)
36 |
37 | .PHONY: all clean
38 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/BCBuilder/AngelScript.bpg:
--------------------------------------------------------------------------------
1 | #------------------------------------------------------------------------------
2 | VERSION = BWS.01
3 | #------------------------------------------------------------------------------
4 | !ifndef ROOT
5 | ROOT = $(MAKEDIR)\..
6 | !endif
7 | #------------------------------------------------------------------------------
8 | MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$**
9 | DCC = $(ROOT)\bin\dcc32.exe $**
10 | BRCC = $(ROOT)\bin\brcc32.exe $**
11 | #------------------------------------------------------------------------------
12 | PROJECTS = AngelScriptBCC_Static_CB6.lib test_feature_CB6.exe
13 | #------------------------------------------------------------------------------
14 | default: $(PROJECTS)
15 | #------------------------------------------------------------------------------
16 |
17 | AngelScriptBCC_Static_CB6.lib: AngelScriptBCC_Static_CB6.bpr
18 | $(ROOT)\bin\bpr2mak -t$(ROOT)\bin\deflib.bmk $**
19 | $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak
20 |
21 | test_feature_CB6.exe: ..\..\..\tests\test_feature\projects\BCBuilder\test_feature_CB6.bpr
22 | $(ROOT)\bin\bpr2mak $**
23 | $(ROOT)\bin\make -$(MAKEFLAGS) -f$*.mak
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/projects/msvc10/msvc10.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual C++ Express 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc10", "msvc10.vcxproj", "{D382A91E-AD6C-4689-894B-82DD0955015F}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|Win32.Build.0 = Debug|Win32
16 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|x64.ActiveCfg = Debug|Win32
17 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|Win32.ActiveCfg = Release|Win32
18 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|Win32.Build.0 = Release|Win32
19 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|x64.ActiveCfg = Release|Win32
20 | EndGlobalSection
21 | GlobalSection(SolutionProperties) = preSolution
22 | HideSolutionNode = FALSE
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/sdk/samples/console/projects/mingw/makefile:
--------------------------------------------------------------------------------
1 | # Console MingW makefile
2 |
3 | CXX = g++
4 | CXXFLAGS ?= -ggdb
5 | CXXFLAGS += -I../../../../angelscript/include
6 | SRCDIR = ../../source
7 | OBJDIR = obj
8 |
9 | SRCNAMES = \
10 | main.cpp \
11 |
12 |
13 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) \
14 | obj/scriptarray.o \
15 | obj/scripthelper.o \
16 | obj/scriptstdstring.o
17 |
18 |
19 | BIN = ../../bin/console.exe
20 | OBJ_D = $(subst /,\,$(OBJ))
21 | BIN_D = $(subst /,\,$(BIN))
22 | DELETER = del /f
23 |
24 | all: $(BIN)
25 |
26 | $(BIN): $(OBJ)
27 | $(CXX) -o $(BIN) $(OBJ) $(CXXFLAGS) -langelscript -L ../../../../angelscript/lib
28 | @echo -------------------------------------------------------------------
29 | @echo Done.
30 |
31 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
32 | $(CXX) $(CXXFLAGS) -o $@ -c $<
33 |
34 | obj/scriptarray.o: ../../../../add_on/scriptarray/scriptarray.cpp
35 | $(CXX) $(CXXFLAGS) -o $@ -c $<
36 |
37 | obj/scripthelper.o: ../../../../add_on/scripthelper/scripthelper.cpp
38 | $(CXX) $(CXXFLAGS) -o $@ -c $<
39 |
40 | obj/scriptstdstring.o: ../../../../add_on/scriptstdstring/scriptstdstring.cpp
41 | $(CXX) $(CXXFLAGS) -o $@ -c $<
42 |
43 | clean:
44 | $(DELETER) $(OBJ_D) $(BIN_D)
45 |
46 | .PHONY: all clean
47 |
--------------------------------------------------------------------------------
/sdk/samples/game/bin/player.as:
--------------------------------------------------------------------------------
1 | // Include the shared code
2 | #include 'shared.as'
3 |
4 | // This script implements the logic for the player character
5 | class CPlayer : IController
6 | {
7 | // The constructor must take a CGameObj handle as input,
8 | // this is the object that the script will control
9 | CPlayer(CGameObj @obj)
10 | {
11 | // Keep the owner for later reference
12 | @self = obj;
13 | }
14 |
15 | void OnThink()
16 | {
17 | // What do the player want to do?
18 | int dx = 0, dy = 0;
19 | if( game.actionState[UP] )
20 | dy--;
21 | if( game.actionState[DOWN] )
22 | dy++;
23 | if( game.actionState[LEFT] )
24 | dx--;
25 | if( game.actionState[RIGHT] )
26 | dx++;
27 | if( !self.Move(dx,dy) )
28 | {
29 | // It wasn't possible to move there.
30 | // Is there a zombie in front of us?
31 | // TODO:
32 | }
33 | }
34 |
35 | void OnMessage(ref @m, const CGameObj @sender)
36 | {
37 | CMessage @msg = cast(m);
38 | if( msg !is null && msg.txt == 'Attack' )
39 | {
40 | // The zombie got us
41 | self.Kill();
42 | game.EndGame(false);
43 | }
44 | }
45 |
46 | CGameObj @self;
47 | }
48 |
49 |
50 | // These are the actions that the user can do
51 | enum EAction
52 | {
53 | UP = 0,
54 | DOWN = 1,
55 | LEFT = 2,
56 | RIGHT = 3
57 | }
58 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testlongtoken.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests to verify that long tokens doesn't crash the library
3 | //
4 |
5 | #include "utils.h"
6 |
7 | static const char * const TESTNAME = "TestLongToken";
8 |
9 |
10 | bool TestLongToken()
11 | {
12 | bool fail = false;
13 | CBufferedOutStream bout;
14 |
15 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
16 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
17 |
18 |
19 | std::string str;
20 |
21 | str.resize(400);
22 | memset(&str[0], 'a', 400);
23 | str += " = 1";
24 |
25 | int r = ExecuteString(engine, str.c_str());
26 | if (r >= 0)
27 | TEST_FAILED;
28 |
29 | engine->Release();
30 |
31 | if (bout.buffer != "ExecuteString (1, 1) : Error : No matching symbol 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n")
32 | {
33 | PRINTF("%s", bout.buffer.c_str());
34 | TEST_FAILED;
35 | }
36 |
37 | // Success
38 | return fail;
39 | }
40 |
--------------------------------------------------------------------------------
/sdk/tests/test_performance/projects/gnuc/makefile:
--------------------------------------------------------------------------------
1 | # Test Framework GNUC makefile
2 |
3 |
4 |
5 | CXX = g++
6 |
7 | CXXFLAGS = -ggdb -I../../../../angelscript/include -Wno-missing-field-initializers
8 | SRCDIR = ../../source
9 | OBJDIR = obj
10 |
11 |
12 | SRCNAMES = \
13 | main.cpp \
14 |
15 | test_basic2.cpp \
16 | test_basic.cpp \
17 | test_call2.cpp \
18 | test_call.cpp \
19 | test_fib.cpp \
20 |
21 | test_int.cpp \
22 | test_intf.cpp \
23 |
24 | test_mthd.cpp \
25 | test_string2.cpp \
26 | test_string.cpp \
27 |
28 | test_string_pooled.cpp \
29 | test_thisprop.cpp \
30 | test_vector3.cpp \
31 | utils.cpp
32 |
33 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) \
34 | obj/scriptstring.o
35 |
36 |
37 |
38 | BIN = ../../bin/testgnuc
39 | DELETER = rm -f
40 |
41 |
42 |
43 | all: $(BIN)
44 |
45 |
46 | $(BIN): $(OBJ)
47 |
48 | $(CXX) -o $(BIN) $(OBJ) -langelscript -lpthread -L../../../../angelscript/lib
49 | @echo -------------------------------------------------------------------
50 | @echo Done.
51 |
52 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
53 | $(CXX) $(CXXFLAGS) -o $@ -c $<
54 |
55 | obj/scriptstring.o: ../../../../add_on/scriptstring/scriptstring.cpp
56 |
57 | $(CXX) $(CXXFLAGS) -o $@ -c $<
58 |
59 | clean:
60 | $(DELETER) $(OBJ) $(BIN)
61 |
62 | .PHONY: all clean
--------------------------------------------------------------------------------
/sdk/tests/test_multithread/source/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #if defined(_MSC_VER)
4 | #include
5 | #endif
6 |
7 | namespace TestSharedString { bool Test(); }
8 | namespace TestThreadMgr { bool Test(); }
9 | namespace TestGC { bool Test(); }
10 |
11 | void DetectMemoryLeaks()
12 | {
13 | #if defined(_MSC_VER)
14 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
15 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
16 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
17 | #endif
18 | }
19 |
20 | int main(int argc, char **argv)
21 | {
22 | DetectMemoryLeaks();
23 |
24 | if( TestSharedString::Test() ) goto failed; else printf("TestSharedString passed\n");
25 | if( TestThreadMgr::Test() ) goto failed; else printf("TestThreadMgr passed\n");
26 | if( TestGC::Test() ) goto failed; else printf("TestGC passed\n");
27 |
28 | printf("--------------------------------------------\n");
29 | printf("All of the tests passed with success.\n\n");
30 | printf("Press any key to quit.\n");
31 | while(!_getch());
32 | return 0;
33 |
34 | failed:
35 | printf("--------------------------------------------\n");
36 | printf("One of the tests failed, see details above.\n\n");
37 | printf("Press any key to quit.\n");
38 | while(!_getch());
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/sdk/tests/test_build_performance/source/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 | #include
3 |
4 | #include
5 | #include
6 |
7 | double ticksPerSecond = 0;
8 | bool timerInitialized = false;
9 | bool usePerformance = false;
10 | double performanceBase = 0;
11 | double GetSystemTimer()
12 | {
13 | if( !timerInitialized )
14 | {
15 | // We need to know how often the clock is updated
16 | __int64 tps;
17 | if( !QueryPerformanceFrequency((LARGE_INTEGER *)&tps) )
18 | usePerformance = false;
19 | else
20 | {
21 | usePerformance = true;
22 | ticksPerSecond = (double)tps;
23 |
24 | __int64 ticks;
25 | QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
26 | performanceBase = (double)ticks/ticksPerSecond;
27 | }
28 |
29 | timerInitialized = true;
30 | }
31 |
32 | if( usePerformance )
33 | {
34 | __int64 ticks;
35 | QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
36 |
37 | double t = (double)ticks/ticksPerSecond - performanceBase;
38 |
39 | // We need to calibrate the performance timer as it is known to jump from time to time
40 | double t2 = (double)timeGetTime()/1000.0;
41 | if( fabs(t-t2) > 0.1 )
42 | {
43 | performanceBase += t - t2;
44 | t = t2;
45 | }
46 |
47 | return t;
48 | }
49 | else
50 | return (double)timeGetTime()/1000.0;
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/bstr.h:
--------------------------------------------------------------------------------
1 | #ifndef BSTR_H
2 | #define BSTR_H
3 |
4 | #include
5 |
6 | #ifdef AS_USE_NAMESPACE
7 | namespace AngelScript
8 | {
9 | #endif
10 |
11 | void RegisterBStr(asIScriptEngine *engine);
12 |
13 | typedef unsigned char * asBSTR;
14 |
15 | asBSTR asBStrAlloc(asUINT length);
16 | void asBStrFree(asBSTR str);
17 | asUINT asBStrLength(asBSTR str);
18 |
19 | asBSTR asBStrConcatenate(const asBSTR *left, const asBSTR *right);
20 |
21 | int asBStrCompare(const asBSTR *s1, const asBSTR *s2);
22 |
23 | bool asBStrEqual(const asBSTR *left, const asBSTR *right);
24 | bool asBStrNotEqual(const asBSTR *left, const asBSTR *right);
25 | bool asBStrLessThan(const asBSTR *left, const asBSTR *right);
26 | bool asBStrLessThanOrEqual(const asBSTR *left, const asBSTR *right);
27 | bool asBStrGreaterThan(const asBSTR *left, const asBSTR *right);
28 | bool asBStrGreaterThanOrEqual(const asBSTR *left, const asBSTR *right);
29 |
30 | asBSTR asBStrFormat(int number);
31 | asBSTR asBStrFormat(unsigned int number);
32 | asBSTR asBStrFormat(float number);
33 | asBSTR asBStrFormat(double number);
34 | asBSTR asBStrFormatBits(asDWORD bits);
35 |
36 | asBSTR asBStrSubstr(const asBSTR &str, asUINT start, asUINT count);
37 |
38 | #ifdef AS_USE_NAMESPACE
39 | }
40 | #endif
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc10/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/tests/test_build_performance/source/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #if defined(_MSC_VER)
4 | #include
5 | #endif
6 | #include "angelscript.h"
7 |
8 | namespace TestBasic { void Test(); }
9 | namespace TestBigArrays { void Test(); }
10 | namespace TestManySymbols { void Test(); }
11 | namespace TestManyFuncs { void Test(); }
12 | namespace TestComplex { void Test(); }
13 | namespace TestRebuild { void Test(); }
14 | namespace TestHugeAPI { void Test(); }
15 |
16 | void DetectMemoryLeaks()
17 | {
18 | #if defined(_MSC_VER)
19 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
20 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
21 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
22 | #endif
23 | }
24 |
25 | int main(int argc, char **argv)
26 | {
27 | DetectMemoryLeaks();
28 |
29 | printf("Build performance test");
30 | #ifdef _DEBUG
31 | printf(" (DEBUG)");
32 | #endif
33 | printf("\n");
34 | printf("AngelScript %s\n", asGetLibraryVersion());
35 |
36 | TestBasic::Test();
37 | TestBigArrays::Test();
38 | TestManySymbols::Test();
39 | TestManyFuncs::Test();
40 | TestComplex::Test();
41 | TestRebuild::Test();
42 | TestHugeAPI::Test();
43 |
44 | printf("--------------------------------------------\n");
45 | printf("Press any key to quit.\n");
46 | while(!getch());
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/sdk/tests/test_build_performance/source/memory_stream.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Interface of Angelscript Stream for reading and writing in main memory
3 | */
4 | #ifndef _AS_TEST_MEMORY_STREAM_H
5 | #define _AS_TEST_MEMORY_STREAM_H
6 |
7 | #include
8 | #include
9 | #include "utils.h"
10 | #include "angelscript.h"
11 |
12 | class CBytecodeStream : public asIBinaryStream
13 | {
14 | public:
15 | CBytecodeStream(const char *name) {wpointer = 0;rpointer = 0;}
16 |
17 | int Write(const void *ptr, asUINT size)
18 | {
19 | if( size == 0 ) return 0;
20 | buffer.resize(buffer.size() + size);
21 | memcpy(&buffer[wpointer], ptr, size);
22 | wpointer += size;
23 | // Are we writing zeroes?
24 | for( asUINT n = 0; n < size; n++ )
25 | if( *(asBYTE*)ptr == 0 )
26 | {
27 | n = n; // <== Set break point here
28 | break;
29 | }
30 | return 0;
31 | }
32 | int Read(void *ptr, asUINT size)
33 | {
34 | if (rpointer + size > buffer.size())
35 | return -1;
36 | memcpy(ptr, &buffer[rpointer], size);
37 | rpointer += size;
38 | return 0;
39 | }
40 | void Restart() {rpointer = 0;}
41 |
42 | asUINT CountZeroes() { asUINT z = 0; for( asUINT n = 0; n < buffer.size(); n++ ) if( buffer[n] == 0 ) z++; return z; }
43 | std::vector buffer;
44 |
45 | protected:
46 | int rpointer;
47 | int wpointer;
48 | };
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/projects/msvc9/msvc9.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual C++ Express 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc9", "msvc9.vcproj", "{D382A91E-AD6C-4689-894B-82DD0955015F}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|Win32.Build.0 = Debug|Win32
16 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|x64.ActiveCfg = Debug|x64
17 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Debug|x64.Build.0 = Debug|x64
18 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|Win32.ActiveCfg = Release|Win32
19 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|Win32.Build.0 = Release|Win32
20 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|x64.ActiveCfg = Release|x64
21 | {D382A91E-AD6C-4689-894B-82DD0955015F}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2012/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc9/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual C++ Express 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2013/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2015/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2017/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2019/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/msvc2022/angelscript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2012 for Windows Desktop
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angelscript", "angelscript.vcxproj", "{39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Debug|x64 = Debug|x64
10 | Release|Win32 = Release|Win32
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|Win32.Build.0 = Debug|Win32
16 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.ActiveCfg = Debug|x64
17 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Debug|x64.Build.0 = Debug|x64
18 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.ActiveCfg = Release|Win32
19 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|Win32.Build.0 = Release|Win32
20 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.ActiveCfg = Release|x64
21 | {39E6AF97-6BA3-4A72-8C61-BCEBF214EBFD}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/sdk/samples/coroutine/projects/gnuc/makefile:
--------------------------------------------------------------------------------
1 | # Tutoral GCC Makefile
2 |
3 | CXX = g++
4 | CXXFLAGS = -std=c++11 -ggdb -I../../../../angelscript/include
5 | SRCDIR = ../../source
6 | OBJDIR = obj
7 |
8 | SRCNAMES = main.cpp
9 |
10 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) obj/scriptstdstring.o obj/contextmgr.o obj/scriptany.o obj/scriptdictionary.o obj/scriptarray.o
11 | BIN = ../../bin/coroutine
12 | DELETER = rm -f
13 |
14 | all: $(BIN)
15 |
16 | $(BIN): $(OBJ)
17 | $(CXX) -o $(BIN) $(OBJ) -static -langelscript -dynamic -L ../../../../angelscript/lib -lpthread
18 | @echo -------------------------------------------------------------------
19 | @echo Done.
20 |
21 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
22 | $(CXX) $(CXXFLAGS) -o $@ -c $<
23 |
24 | obj/scriptarray.o: ../../../../add_on/scriptarray/scriptarray.cpp
25 | $(CXX) $(CXXFLAGS) -o $@ -c $<
26 |
27 | obj/scriptdictionary.o: ../../../../add_on/scriptdictionary/scriptdictionary.cpp
28 | $(CXX) $(CXXFLAGS) -o $@ -c $<
29 |
30 | obj/scriptstdstring.o: ../../../../add_on/scriptstdstring/scriptstdstring.cpp
31 | $(CXX) $(CXXFLAGS) -o $@ -c $<
32 |
33 | obj/contextmgr.o: ../../../../add_on/contextmgr/contextmgr.cpp
34 | $(CXX) $(CXXFLAGS) -o $@ -c $<
35 |
36 | obj/scriptany.o: ../../../../add_on/scriptany/scriptany.cpp
37 | $(CXX) $(CXXFLAGS) -o $@ -c $<
38 |
39 | clean:
40 | $(DELETER) $(OBJ) $(BIN)
41 |
42 | .PHONY: all clean
43 |
--------------------------------------------------------------------------------
/sdk/docs/doxygen/source/doc_arrays.h:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | \page doc_arrays Custom array type
4 |
5 | Like the \ref doc_strings "string type", AngelScript doesn't have a built-in
6 | dynamic array type. Instead the application developers that wishes to allow
7 | dynamic arrays in the scripts should register this in the way that is best
8 | suited for the application. To save time a readily usable add-on is provided
9 | with a fully implemented \ref doc_addon_array "dynamic array type".
10 |
11 | If you wish to create your own array type, you'll need to understand how
12 | \ref doc_adv_template "template types" work. A template type is a special form
13 | of registering a type that the engine can then use to instanciate the true
14 | types based on the desired sub-types. This allow a single type registration to
15 | cover all possible array types that the script may need, instead of the
16 | application having to register a specific type for each type of array.
17 |
18 | Of course, a generic type like this will have a drawback in performance due to
19 | runtime checks to determine the actual type, so the application should consider
20 | registering \ref doc_adv_template_2 "template specializations" of the most
21 | common array types. This will allow the best optimizations for those types, and
22 | will also permit better interaction with the application as the template
23 | specialization can better match the actual array types that the application
24 | uses.
25 |
26 | */
27 |
--------------------------------------------------------------------------------
/sdk/samples/game/projects/gnuc/makefile:
--------------------------------------------------------------------------------
1 | # Test Framework GNUC makefile
2 |
3 | CXX = g++
4 | CXXFLAGS += -ggdb -I../../../../angelscript/include -Wno-missing-field-initializers
5 | SRCDIR = ../../source
6 | OBJDIR = obj
7 |
8 | ifdef DONT_WAIT
9 | CXXFLAGS += -DDONT_WAIT
10 | endif
11 |
12 |
13 | SRCNAMES = \
14 | main.cpp \
15 | gamemgr.cpp \
16 | gameobj.cpp \
17 | scriptmgr.cpp \
18 |
19 |
20 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) \
21 | obj/scripthandle.o \
22 | obj/scriptstdstring.o \
23 | obj/scriptbuilder.o \
24 | obj/weakref.o \
25 |
26 |
27 | BIN = ../../bin/game
28 | DELETER = rm -f
29 |
30 | all: $(BIN)
31 |
32 | $(BIN): $(OBJ)
33 | $(CXX) $(LDFLAGS) -o $(BIN) $(OBJ) -static -langelscript -dynamic -lpthread -L../../../../angelscript/lib
34 | @echo -------------------------------------------------------------------
35 | @echo Done.
36 |
37 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
38 | $(CXX) $(CXXFLAGS) -o $@ -c $<
39 |
40 | obj/scripthandle.o: ../../../../add_on/scripthandle/scripthandle.cpp
41 | $(CXX) $(CXXFLAGS) -o $@ -c $<
42 |
43 | obj/scriptstdstring.o: ../../../../add_on/scriptstdstring/scriptstdstring.cpp
44 | $(CXX) $(CXXFLAGS) -o $@ -c $<
45 |
46 | obj/scriptbuilder.o: ../../../../add_on/scriptbuilder/scriptbuilder.cpp
47 | $(CXX) $(CXXFLAGS) -o $@ -c $<
48 |
49 | obj/weakref.o: ../../../../add_on/weakref/weakref.cpp
50 | $(CXX) $(CXXFLAGS) -o $@ -c $<
51 |
52 | clean:
53 | $(DELETER) $(OBJ) $(BIN)
54 |
55 | .PHONY: all clean
56 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testexecute2args.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests calling of a c-function from a script with two parameters
3 | //
4 | // Test author: Fredrik Ehnbom
5 | //
6 |
7 | #include "utils.h"
8 |
9 | static const char * const TESTNAME = "TestExecute2Args";
10 |
11 | static int testVal = 0;
12 | static bool called = false;
13 |
14 | static void cfunction(int f1, int f2)
15 | {
16 | called = true;
17 | testVal = f1 + f2;
18 | }
19 |
20 | static void cfunction_gen(asIScriptGeneric *gen)
21 | {
22 | called = true;
23 | testVal = (int)gen->GetArgDWord(0) + (int)gen->GetArgDWord(1);
24 | }
25 |
26 | bool TestExecute2Args()
27 | {
28 | bool fail = false;
29 |
30 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
31 | if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
32 | engine->RegisterGlobalFunction("void cfunction(int, int)", asFUNCTION(cfunction_gen), asCALL_GENERIC);
33 | else
34 | engine->RegisterGlobalFunction("void cfunction(int, int)", asFUNCTION(cfunction), asCALL_CDECL);
35 |
36 | ExecuteString(engine, "cfunction(5, 9)");
37 |
38 | if( !called )
39 | {
40 | // failure
41 | PRINTF("\n%s: cfunction not called from script\n\n", TESTNAME);
42 | TEST_FAILED;
43 | }
44 | else if( testVal != (5 + 9) )
45 | {
46 | // failure
47 | PRINTF("\n%s: testVal is not of expected value. Got %d, expected %d\n\n", TESTNAME, testVal, (5 + 9));
48 | TEST_FAILED;
49 | }
50 |
51 | engine->Release();
52 |
53 | // Success
54 | return fail;
55 | }
56 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/test_2func.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests compiling with 2 equal functions
3 | //
4 | // Test author: Andreas Jonsson
5 | //
6 |
7 | #include "utils.h"
8 |
9 | namespace Test2Func
10 | {
11 |
12 | static const char * const TESTNAME = "Test2Func";
13 |
14 |
15 | static const char *script1 =
16 | "void Test() { } \n"
17 | "void Test() { } \n";
18 |
19 | static const char *script2 =
20 | "void Test(void) { } \n";
21 |
22 | bool Test()
23 | {
24 | bool fail = false;
25 | int r;
26 | CBufferedOutStream out;
27 |
28 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
29 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &out, asCALL_THISCALL);
30 |
31 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
32 | mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0);
33 | mod->Build();
34 |
35 | if( out.buffer != "Test2Func (2, 1) : Error : A function with the same name and parameters already exists\n" )
36 | {
37 | TEST_FAILED;
38 | PRINTF("%s: Failed to identify the error with two equal functions\n", TESTNAME);
39 | }
40 |
41 | out.buffer = "";
42 | mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
43 | mod->AddScriptSection(TESTNAME, script2, strlen(script2), 0);
44 | r = mod->Build();
45 | if( r < 0 ) TEST_FAILED;
46 | if( out.buffer != "" )
47 | TEST_FAILED;
48 |
49 |
50 |
51 |
52 |
53 | engine->Release();
54 |
55 | if( fail )
56 | {
57 | PRINTF("%s: failed\n", TESTNAME);
58 | }
59 |
60 | // Success
61 | return fail;
62 | }
63 |
64 | } // namespace
65 |
66 |
--------------------------------------------------------------------------------
/sdk/angelscript/projects/android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | # This makefile assumes the ndk-build tool is executed from the sdk/angelscript/projects/android directory
2 | # Change the next line to full path if there are any errors to link or find files
3 | SDK_BASE_PATH := $(call my-dir)/../../../..
4 |
5 | ANGELSCRIPT_INCLUDE := $(SDK_BASE_PATH)/angelscript/include/
6 |
7 | # -----------------------------------------------------
8 | # Build the AngelScript library
9 | # -----------------------------------------------------
10 | include $(CLEAR_VARS)
11 | LOCAL_MODULE := libangelscript
12 |
13 | # Android API: Checks if can use pthreads. Version 2.3 fully supports threads and atomic instructions
14 | # ifeq ($(TARGET_PLATFORM),android-3)
15 | # LOCAL_CFLAGS := -DAS_NO_THREADS
16 | # else
17 | # ifeq ($(TARGET_PLATFORM),android-4)
18 | # LOCAL_CFLAGS := -DAS_NO_THREADS
19 | # else
20 | # ifeq ($(TARGET_PLATFORM),android-5)
21 | # LOCAL_CFLAGS := -DAS_NO_THREADS
22 | # else
23 | # ifeq ($(TARGET_PLATFORM),android-6)
24 | # LOCAL_CFLAGS := -DAS_NO_THREADS
25 | # else
26 | # ifeq ($(TARGET_PLATFORM),android-7)
27 | # LOCAL_CFLAGS := -DAS_NO_THREADS
28 | # else
29 | # ifeq ($(TARGET_PLATFORM),android-8)
30 | # LOCAL_CFLAGS := -DAS_NO_THREADS
31 | # endif
32 | # endif
33 | # endif
34 | # endif
35 | # endif
36 | # endif
37 |
38 | LOCAL_CPP_FEATURES += rtti exceptions
39 | LOCAL_SRC_FILES := $(wildcard $(SDK_BASE_PATH)/angelscript/source/*.S)
40 | LOCAL_SRC_FILES += $(wildcard $(SDK_BASE_PATH)/angelscript/source/*.cpp)
41 | LOCAL_PATH := .
42 | LOCAL_ARM_MODE := arm
43 | include $(BUILD_STATIC_LIBRARY)
44 |
--------------------------------------------------------------------------------
/sdk/add_on/scriptsocket/scriptsocket.h:
--------------------------------------------------------------------------------
1 | //
2 | // CScriptSocket
3 | //
4 | // This class represents a socket. It can be used to set up listeners for
5 | // connecting incoming clients, and also to connect to a server. The socket
6 | // class will create threads in the background to handle the communication
7 | // and update a send and a receive buffer so the script will not have to deal
8 | // with that.
9 | //
10 |
11 | #ifndef SCRIPTSOCKET_H
12 | #define SCRIPTSOCKET_H
13 |
14 | #include
15 | #include
16 | #ifdef _WIN32
17 | #include
18 | #endif
19 |
20 | #ifndef ANGELSCRIPT_H
21 | // Avoid having to inform include path if header is already include before
22 | #include
23 | #endif
24 |
25 | BEGIN_AS_NAMESPACE
26 |
27 | #ifdef _WIN32
28 |
29 | class CScriptSocket
30 | {
31 | public:
32 | CScriptSocket();
33 |
34 | // Memory management
35 | void AddRef() const;
36 | void Release() const;
37 |
38 | // Methods
39 | int Listen(asWORD port);
40 | int Close();
41 | CScriptSocket* Accept(asINT64 timeoutMicrosec = 0);
42 | int Connect(asUINT ipv4Address, asWORD port);
43 | int Send(const std::string& data);
44 | std::string Receive(asINT64 timeoutMicrosec = 0);
45 | bool IsActive() const;
46 |
47 | protected:
48 | ~CScriptSocket();
49 |
50 | int Select(asINT64 timeoutMicrosec = 0);
51 |
52 | mutable int m_refCount;
53 |
54 | int m_socket;
55 | bool m_isListening;
56 | };
57 |
58 | #endif
59 |
60 | int RegisterScriptSocket(asIScriptEngine* engine);
61 |
62 | END_AS_NAMESPACE
63 |
64 | #endif
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testcreateengine.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Test to see if engine can be created.
3 | //
4 | // Author: Fredrik Ehnbom
5 | //
6 |
7 | #include "utils.h"
8 |
9 | bool TestCreateEngine()
10 | {
11 | bool fail = false;
12 | asIScriptEngine *engine = asCreateScriptEngine();
13 | if( engine == 0 )
14 | {
15 | // Failure
16 | PRINTF("TestCreateEngine: asCreateScriptEngine() failed\n");
17 | TEST_FAILED;
18 | }
19 | else
20 | {
21 | // Set a message callback
22 | CBufferedOutStream bout;
23 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
24 |
25 | // Although it's not recommended that two engines are created, it shouldn't be a problem
26 | asIScriptEngine *engine2 = asCreateScriptEngine();
27 | if( engine2 == 0 )
28 | {
29 | // Failure
30 | PRINTF("TestCreateEngine: asCreateScriptEngine() failed for 2nd engine\n");
31 | TEST_FAILED;
32 | }
33 | else
34 | {
35 | // Attempt to reuse the message callback from the first engine
36 | asSFuncPtr msgCallback;
37 | void* obj;
38 | asDWORD callConv;
39 | engine->GetMessageCallback(&msgCallback, &obj, &callConv);
40 | engine2->SetMessageCallback(msgCallback, obj, callConv);
41 |
42 | engine2->WriteMessage("test", 0, 0, asMSGTYPE_INFORMATION, "Hello from engine2");
43 |
44 | engine2->ShutDownAndRelease();
45 | }
46 |
47 | engine->ShutDownAndRelease();
48 |
49 | if (bout.buffer != "test (0, 0) : Info : Hello from engine2\n")
50 | {
51 | PRINTF("%s", bout.buffer.c_str());
52 | TEST_FAILED;
53 | }
54 | }
55 |
56 | return fail;
57 | }
58 |
--------------------------------------------------------------------------------
/sdk/docs/doxygen/source/touch.js:
--------------------------------------------------------------------------------
1 | // Code provided by Alex Andreotti based on the information found here:
2 | // http://chris-barr.com/2010/05/scrolling_a_overflowauto_element_on_a_touch_screen_device/
3 |
4 | function isTouchDevice(){
5 | try{
6 | document.createEvent("TouchEvent");
7 | return true;
8 | }catch(e){
9 | return false;
10 | }
11 | }
12 |
13 | function touchScroll(el){
14 | if(isTouchDevice()){
15 | var scrollStartPos=0;
16 | var lastPos=0;
17 | var delta=0;
18 | var capture=false;
19 |
20 | el.addEventListener("touchstart", function(event) {
21 | scrollStartPos=this.scrollTop+event.touches[0].pageY;
22 | lastPos = event.touches[0].pageY;
23 | if (capture) {
24 | event.preventDefault();
25 | capture = false;
26 | }
27 | },false);
28 |
29 | el.addEventListener("touchmove", function(event) {
30 | var deltaY = scrollStartPos-event.touches[0].pageY;
31 | delta = event.touches[0].pageY - lastPos;
32 | //document.title = deltaY+':'+lastPos+':'+delta;
33 | this.velocity = delta;
34 | lastPos = event.touches[0].pageY;
35 | if (delta == 0) {
36 | capture = false;
37 | } else {
38 | capture = !(delta <= 0 && this.scrollTop+this.clientHeight==this.scrollHeight) && !(delta >= 0 && this.scrollTop == 0);
39 | }
40 | if (capture) {
41 | this.scrollTop = deltaY;
42 | event.preventDefault();
43 | }
44 | },false);
45 | }
46 | }
47 |
48 | // Add the touchScroll event handler to the nav-tree and main content divs
49 | $(document).ready(function() {
50 | $('#doc-content, #nav-tree').each(function(){ touchScroll(this); });
51 | });
52 |
53 |
--------------------------------------------------------------------------------
/sdk/tests/test_build_performance/projects/gnuc/makefile:
--------------------------------------------------------------------------------
1 | # Tutoral GCC Makefile
2 | CXX = g++
3 | #CXX = i686-pc-mingw32-g++.exe
4 | CXXFLAGS = -O0 -g -I../../../../angelscript/include -I../../../../angelscript/source -D_LINUX_
5 | CXXADDFLAGS =
6 | ifdef PROFILE
7 | CXXFLAGS += -pg
8 | CXXADDFLAGS = -pg
9 | endif
10 | #CXXFLAGS = -O0 -g -I../../../../angelscript/include
11 | SRCDIR = ../../source
12 | ADDONDIR = ../../../../add_on
13 | ADDONS =
14 |
15 | OBJDIR = obj
16 | SRCNAMES = \
17 | main.cpp \
18 | test_basic.cpp \
19 | test_big_arrays.cpp \
20 | test_complex.cpp \
21 | test_many_symbols.cpp \
22 | test_many_funcs.cpp \
23 | utils.cpp
24 |
25 | OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o))) \
26 | obj/scriptstdstring.o \
27 | obj/scriptstdstring_utils.o \
28 | obj/scriptarray.o
29 |
30 | BIN = ../../bin/asrun
31 | DELETER = rm -f
32 | all: $(BIN)
33 | $(BIN): $(OBJ)
34 | $(CXX) -static $(CXXADDFLAGS) -o $(BIN) $(OBJ) -langelscript -lpthread -L ../../../../angelscript/lib
35 | @echo -------------------------------------------------------------------
36 | @echo Done.
37 | $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
38 | $(CXX) $(CXXFLAGS) -o $@ -c $<
39 |
40 | obj/scriptstdstring.o: ../../../../add_on/scriptstdstring/scriptstdstring.cpp
41 | $(CXX) $(CXXFLAGS) -o $@ -c $<
42 |
43 | obj/scriptstdstring_utils.o: ../../../../add_on/scriptstdstring/scriptstdstring_utils.cpp
44 | $(CXX) $(CXXFLAGS) -o $@ -c $<
45 |
46 | obj/scriptarray.o: ../../../../add_on/scriptarray/scriptarray.cpp
47 | $(CXX) $(CXXFLAGS) -o $@ -c $<
48 |
49 | clean:
50 | $(DELETER) $(OBJ) $(BIN)
51 | .PHONY: all clean
52 |
--------------------------------------------------------------------------------
/sdk/add_on/scriptstdstring/scriptstdstring.h:
--------------------------------------------------------------------------------
1 | //
2 | // Script std::string
3 | //
4 | // This function registers the std::string type with AngelScript to be used as the default string type.
5 | //
6 | // The string type is registered as a value type, thus may have performance issues if a lot of
7 | // string operations are performed in the script. However, for relatively few operations, this should
8 | // not cause any problem for most applications.
9 | //
10 |
11 | #ifndef SCRIPTSTDSTRING_H
12 | #define SCRIPTSTDSTRING_H
13 |
14 | #ifndef ANGELSCRIPT_H
15 | // Avoid having to inform include path if header is already include before
16 | #include
17 | #endif
18 |
19 | #include
20 |
21 | //---------------------------
22 | // Compilation settings
23 | //
24 |
25 | // Sometimes it may be desired to use the same method names as used by C++ STL.
26 | // This may for example reduce time when converting code from script to C++ or
27 | // back.
28 | //
29 | // 0 = off
30 | // 1 = on
31 | #ifndef AS_USE_STLNAMES
32 | #define AS_USE_STLNAMES 0
33 | #endif
34 |
35 | // Some prefer to use property accessors to get/set the length of the string
36 | // This option registers the accessors instead of the method length()
37 | #ifndef AS_USE_ACCESSORS
38 | #define AS_USE_ACCESSORS 0
39 | #endif
40 |
41 | // This option disables the implicit operators with primitives
42 | #ifndef AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE
43 | #define AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE 0
44 | #endif
45 |
46 | BEGIN_AS_NAMESPACE
47 |
48 | void RegisterStdString(asIScriptEngine *engine);
49 | void RegisterStdStringUtils(asIScriptEngine *engine);
50 |
51 | END_AS_NAMESPACE
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/sdk/docs/doxygen/source/doc_adv_single_ref_type.h:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | \page doc_adv_single_ref_type Registering a single-reference type
4 |
5 | A variant of the uninstanciable reference types is the single-reference
6 | type. This is a type that have only 1 reference accessing it, i.e. the script
7 | cannot store any extra references to the object during execution. The script
8 | is forced to use the reference it receives from the application at the moment
9 | the application passes it on to the script.
10 |
11 | The reference can be passed to the script through a property, either global
12 | or a class member, or it can be returned from an application registered
13 | function or class method.
14 |
15 | The script engine will not permit declaration of functions that take this
16 | type as a parameter, neither as a reference nor as a handle. If that was allowed
17 | it would mean that a reference to the instance is placed on the stack, which
18 | in turn means that it is no longer a single-reference type.
19 |
20 | \code
21 | // Registering the type so that it cannot be instanciated
22 | // by the script, nor allow scripts to store references to the type
23 | r = engine->RegisterObjectType("single", 0, asOBJ_REF | asOBJ_NOHANDLE); assert( r >= 0 );
24 | \endcode
25 |
26 | This sort of type is most useful when you want to have complete control over
27 | references to an object, for example so that the application can destroy and
28 | recreate objects of the type without having to worry about potential references
29 | held by scripts. This allows the application to control when a script has access
30 | to an object and it's members.
31 |
32 |
33 | \see \ref doc_reg_basicref
34 |
35 |
36 |
37 | */
38 |
--------------------------------------------------------------------------------
/sdk/add_on/weakref/weakref.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTWEAKREF_H
2 | #define SCRIPTWEAKREF_H
3 |
4 | // The CScriptWeakRef class was originally implemented by vroad in March 2013
5 |
6 | #ifndef ANGELSCRIPT_H
7 | // Avoid having to inform include path if header is already include before
8 | #include
9 | #endif
10 |
11 | BEGIN_AS_NAMESPACE
12 |
13 | class CScriptWeakRef
14 | {
15 | public:
16 | // Constructors
17 | CScriptWeakRef(asITypeInfo *type);
18 | CScriptWeakRef(const CScriptWeakRef &other);
19 | CScriptWeakRef(void *ref, asITypeInfo *type);
20 |
21 | ~CScriptWeakRef();
22 |
23 | // Copy the stored value from another weakref object
24 | CScriptWeakRef &operator=(const CScriptWeakRef &other);
25 |
26 | // Compare equalness
27 | bool operator==(const CScriptWeakRef &o) const;
28 | bool operator!=(const CScriptWeakRef &o) const;
29 |
30 | // Sets a new reference
31 | CScriptWeakRef &Set(void *newRef);
32 |
33 | // Returns the object if it is still alive
34 | // This will increment the refCount of the returned object
35 | void *Get() const;
36 |
37 | // Returns true if the contained reference is the same
38 | bool Equals(void *ref) const;
39 |
40 | // Returns the type of the reference held
41 | asITypeInfo *GetRefType() const;
42 |
43 | protected:
44 | // These functions need to have access to protected
45 | // members in order to call them from the script engine
46 | friend void RegisterScriptWeakRef_Native(asIScriptEngine *engine);
47 |
48 | void *m_ref;
49 | asITypeInfo *m_type;
50 | asILockableSharedBool *m_weakRefFlag;
51 | };
52 |
53 | void RegisterScriptWeakRef(asIScriptEngine *engine);
54 |
55 | END_AS_NAMESPACE
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/sdk/add_on/scriptmath/scriptmathcomplex.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTMATHCOMPLEX_H
2 | #define SCRIPTMATHCOMPLEX_H
3 |
4 | #ifndef ANGELSCRIPT_H
5 | // Avoid having to inform include path if header is already include before
6 | #include
7 | #endif
8 |
9 |
10 | BEGIN_AS_NAMESPACE
11 |
12 | // This class implements complex numbers and the common
13 | // operations that can be done with it.
14 | //
15 | // Ref: http://mathworld.wolfram.com/ComplexNumber.html
16 |
17 | struct Complex
18 | {
19 | Complex();
20 | Complex(const Complex &other);
21 | Complex(float r, float i = 0);
22 |
23 | // Assignment operator
24 | Complex &operator=(const Complex &other);
25 |
26 | // Compound assigment operators
27 | Complex &operator+=(const Complex &other);
28 | Complex &operator-=(const Complex &other);
29 | Complex &operator*=(const Complex &other);
30 | Complex &operator/=(const Complex &other);
31 |
32 | float length() const;
33 | float squaredLength() const;
34 |
35 | // Swizzle operators
36 | Complex get_ri() const;
37 | void set_ri(const Complex &in);
38 | Complex get_ir() const;
39 | void set_ir(const Complex &in);
40 |
41 | // Comparison
42 | bool operator==(const Complex &other) const;
43 | bool operator!=(const Complex &other) const;
44 |
45 | // Math operators
46 | Complex operator+(const Complex &other) const;
47 | Complex operator-(const Complex &other) const;
48 | Complex operator*(const Complex &other) const;
49 | Complex operator/(const Complex &other) const;
50 |
51 | float r;
52 | float i;
53 | };
54 |
55 | // This function will determine the configuration of the engine
56 | // and use one of the two functions below to register the string type
57 | void RegisterScriptMathComplex(asIScriptEngine *engine);
58 |
59 | END_AS_NAMESPACE
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/sdk/docs/doxygen/source/doc_adv_import.h:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | \page doc_adv_import Import functions
4 |
5 | \ref doc_global_import "Importing functions" is a form of \ref doc_script_shared "sharing" code between script modules.
6 | Unlike the shared keyword though, the import requires specific code in the application to bind the imported
7 | functions after the script has been compiled.
8 |
9 | This may be useful when the application wants to control specifically what can and cannot be imported.
10 |
11 | To bind all the imported functions, without any specific treatment, the application just needs to call the
12 | \ref asIScriptModule::BindAllImportedFunctions "BindAllImportedFunctions" method after the
13 | \ref doc_compile_script "build" has completed.
14 |
15 | If fine grained control is desired, then the application should use the methods
16 | \ref asIScriptModule::GetImportedFunctionCount "GetImportedFunctionCount",
17 | \ref asIScriptModule::GetImportedFunctionDeclaration "GetImportedFunctionDeclaration",
18 | \ref asIScriptModule::GetImportedFunctionSourceModule "GetImportedFunctionSourceModule",
19 | \ref asIScriptModule::GetFunctionByDecl "GetFunctionByDecl", and
20 | \ref asIScriptModule::BindImportedFunction "BindImportedFunction", to enumerate and bind the imported functions one by one,
21 | and raise an error in case the script tries to import a function that the application doesn't allow.
22 |
23 | Another advantage that the import function feature has over shared entities, is that the imported functions can be unbound and
24 | then bound to another script module if there is a need to change the sourcing module. To unbind the bound functions use the methods
25 | \ref asIScriptModule::UnbindAllImportedFunctions "UnbindAllImportedFunctions" or \ref asIScriptModule::UnbindImportedFunction "UnbindImportedFunction".
26 |
27 |
28 | */
29 |
--------------------------------------------------------------------------------
/sdk/samples/game/source/scriptmgr.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTMGR_H
2 | #define SCRIPTMGR_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "../../../add_on/scripthandle/scripthandle.h"
8 |
9 | class CGameObj;
10 |
11 | class CScriptMgr
12 | {
13 | public:
14 | CScriptMgr();
15 | ~CScriptMgr();
16 |
17 | int Init();
18 |
19 | asIScriptObject *CreateController(const std::string &type, CGameObj *obj);
20 | void CallOnThink(asIScriptObject *object);
21 | void CallOnMessage(asIScriptObject *object, CScriptHandle &msg, CGameObj *caller);
22 |
23 | bool hasCompileErrors;
24 |
25 | protected:
26 | void MessageCallback(const asSMessageInfo &msg);
27 | asIScriptContext *PrepareContextFromPool(asIScriptFunction *func);
28 | void ReturnContextToPool(asIScriptContext *ctx);
29 | int ExecuteCall(asIScriptContext *ctx);
30 |
31 | struct SController
32 | {
33 | SController() : type(0), factoryFunc(0), onThinkMethod(0), onMessageMethod(0) {}
34 | std::string module;
35 | asITypeInfo *type;
36 | asIScriptFunction *factoryFunc;
37 | asIScriptFunction *onThinkMethod;
38 | asIScriptFunction *onMessageMethod;
39 | };
40 |
41 | SController *GetControllerScript(const std::string &type);
42 |
43 | asIScriptEngine *engine;
44 |
45 | // Our pool of script contexts. This is used to avoid allocating
46 | // the context objects all the time. The context objects are quite
47 | // heavy weight and should be shared between function calls.
48 | std::vector contexts;
49 |
50 | // This is the cache of function ids etc that we use to avoid having
51 | // to search for the function ids everytime we need to call a function.
52 | // The search is quite time consuming and should only be done once.
53 | std::vector controllers;
54 | };
55 |
56 | extern CScriptMgr *scriptMgr;
57 |
58 | #endif
--------------------------------------------------------------------------------
/sdk/tests/test_performance/source/test_call.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Test author: Andreas Jonsson
3 | //
4 |
5 | #include "utils.h"
6 |
7 | namespace TestCall
8 | {
9 |
10 | #define TESTNAME "TestCall"
11 |
12 | static const char *script =
13 | "void TestCall() \n"
14 | "{ \n"
15 | "} \n";
16 |
17 |
18 | void Test(double *testTime)
19 | {
20 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
21 | COutStream out;
22 | engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
23 |
24 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
25 | mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
26 | mod->Build();
27 |
28 | #ifndef _DEBUG
29 | asIScriptContext *ctx = engine->CreateContext();
30 | asIScriptFunction *func = mod->GetFunctionByDecl("void TestCall()");
31 |
32 | double time = GetSystemTimer();
33 | int r;
34 |
35 | for( int n = 0; n < 10000000; n++ )
36 | {
37 | ctx->Prepare(func);
38 | r = ctx->Execute();
39 | if( r != 0 ) break;
40 | }
41 |
42 | time = GetSystemTimer() - time;
43 |
44 | if( r != 0 )
45 | {
46 | printf("Execution didn't terminate with asEXECUTION_FINISHED\n");
47 | if( r == asEXECUTION_EXCEPTION )
48 | {
49 | printf("Script exception\n");
50 | asIScriptFunction *func = ctx->GetExceptionFunction();
51 | printf("Func: %s\n", func->GetName());
52 | printf("Line: %d\n", ctx->GetExceptionLineNumber());
53 | printf("Desc: %s\n", ctx->GetExceptionString());
54 | }
55 | }
56 | else
57 | *testTime = time;
58 |
59 | ctx->Release();
60 | #endif
61 | engine->Release();
62 | }
63 |
64 | } // namespace
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testtempvar.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests to verify that temporary variables are
3 | // correctly released when calling object methods.
4 | //
5 | // Author: Peter Marshall (2004/06/14)
6 | //
7 |
8 | #include "utils.h"
9 |
10 | static const char * const TESTNAME = "TestTempVar";
11 |
12 | struct Object1
13 | {
14 | int GetInt(void);
15 | int m_nID;
16 | };
17 | struct Object2
18 | {
19 | Object1 GetObject1(void);
20 | };
21 | int Object1::GetInt(void)
22 | {
23 | return m_nID;
24 | }
25 | Object1 Object2::GetObject1(void)
26 | {
27 | Object1 Object;
28 | Object.m_nID = 0xdeadbeef;
29 | return Object;
30 | }
31 | Object2 ScriptObject;
32 |
33 | bool TestTempVar()
34 | {
35 | RET_ON_MAX_PORT;
36 |
37 | bool fail = false;
38 |
39 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
40 | CBufferedOutStream bout;
41 |
42 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
43 | bout.buffer = "";
44 | engine->RegisterObjectType("Object1", sizeof(Object1), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS | asOBJ_APP_CLASS_ALLINTS);
45 | engine->RegisterObjectMethod("Object1", "int GetInt()", asMETHOD(Object1,GetInt), asCALL_THISCALL);
46 | engine->RegisterObjectType("Object2", sizeof(Object2), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS | asOBJ_APP_CLASS_ALLINTS);
47 | engine->RegisterObjectMethod("Object2", "Object1 GetObject1()", asMETHOD(Object2,GetObject1), asCALL_THISCALL);
48 | engine->RegisterGlobalProperty("Object2 GlobalObject", &ScriptObject);
49 |
50 | int r = ExecuteString(engine, "GlobalObject.GetObject1().GetInt();");
51 | if (r != asEXECUTION_FINISHED)
52 | TEST_FAILED;
53 |
54 | engine->Release();
55 |
56 | if (bout.buffer != "")
57 | {
58 | PRINTF("%s", bout.buffer.c_str());
59 | TEST_FAILED;
60 | }
61 |
62 | // Success
63 | return fail;
64 | }
65 |
--------------------------------------------------------------------------------
/sdk/angelscript/source/as_atomic.h:
--------------------------------------------------------------------------------
1 | /*
2 | AngelCode Scripting Library
3 | Copyright (c) 2003-2013 Andreas Jonsson
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any
7 | damages arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any
10 | purpose, including commercial applications, and to alter it and
11 | redistribute it freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you
14 | must not claim that you wrote the original software. If you use
15 | this software in a product, an acknowledgment in the product
16 | documentation would be appreciated but is not required.
17 |
18 | 2. Altered source versions must be plainly marked as such, and
19 | must not be misrepresented as being the original software.
20 |
21 | 3. This notice may not be removed or altered from any source
22 | distribution.
23 |
24 | The original version of this library can be located at:
25 | http://www.angelcode.com/angelscript/
26 |
27 | Andreas Jonsson
28 | andreas@angelcode.com
29 | */
30 |
31 |
32 | //
33 | // as_atomic.h
34 | //
35 | // The asCAtomic class provides methods for performing threadsafe
36 | // operations on a single dword, e.g. reference counting and
37 | // bitfields.
38 | //
39 |
40 |
41 |
42 | #ifndef AS_ATOMIC_H
43 | #define AS_ATOMIC_H
44 |
45 | #include "as_config.h"
46 |
47 | BEGIN_AS_NAMESPACE
48 |
49 | class asCAtomic
50 | {
51 | public:
52 | asCAtomic();
53 |
54 | asDWORD get() const;
55 | void set(asDWORD val);
56 |
57 | // Increase and return new value
58 | asDWORD atomicInc();
59 |
60 | // Decrease and return new value
61 | asDWORD atomicDec();
62 |
63 | protected:
64 | asDWORD value;
65 | };
66 |
67 | END_AS_NAMESPACE
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/sdk/angelscript/source/as_string_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | AngelCode Scripting Library
3 | Copyright (c) 2003-2016 Andreas Jonsson
4 |
5 | This software is provided 'as-is', without any express or implied
6 | warranty. In no event will the authors be held liable for any
7 | damages arising from the use of this software.
8 |
9 | Permission is granted to anyone to use this software for any
10 | purpose, including commercial applications, and to alter it and
11 | redistribute it freely, subject to the following restrictions:
12 |
13 | 1. The origin of this software must not be misrepresented; you
14 | must not claim that you wrote the original software. If you use
15 | this software in a product, an acknowledgment in the product
16 | documentation would be appreciated but is not required.
17 |
18 | 2. Altered source versions must be plainly marked as such, and
19 | must not be misrepresented as being the original software.
20 |
21 | 3. This notice may not be removed or altered from any source
22 | distribution.
23 |
24 | The original version of this library can be located at:
25 | http://www.angelcode.com/angelscript/
26 |
27 | Andreas Jonsson
28 | andreas@angelcode.com
29 | */
30 |
31 |
32 | #ifndef AS_STRING_UTIL_H
33 | #define AS_STRING_UTIL_H
34 |
35 | #include "as_config.h"
36 |
37 | BEGIN_AS_NAMESPACE
38 |
39 | int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len2);
40 |
41 | double asStringScanDouble(const char *string, size_t *numScanned);
42 | asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, bool *overflow);
43 |
44 | int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer);
45 | int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength);
46 |
47 | int asStringEncodeUTF16(unsigned int value, char *outEncodedBuffer);
48 |
49 | END_AS_NAMESPACE
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testexecute4args.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests calling of a c-function from a script with four parameters
3 | //
4 | // Test author: Fredrik Ehnbom
5 | //
6 |
7 | #include "utils.h"
8 |
9 | static const char * const TESTNAME = "TestExecute4Args";
10 |
11 | static bool testVal = false;
12 | static bool called = false;
13 |
14 | static int t1 = 0;
15 | static short t2 = 0;
16 | static char t3 = 0;
17 | static int t4 = 0;
18 |
19 | static void cfunction(int f1, short f2, char f3, int f4)
20 | {
21 | called = true;
22 | t1 = f1;
23 | t2 = f2;
24 | t3 = f3;
25 | t4 = f4;
26 | testVal = (f1 == 5) && (f2 == 9) && (f3 == 1) && (f4 == 3);
27 | }
28 |
29 | static void cfunction_gen(asIScriptGeneric *gen)
30 | {
31 | called = true;
32 | t1 = gen->GetArgDWord(0);
33 | t2 = *(short*)gen->GetAddressOfArg(1);
34 | t3 = *(char*)gen->GetAddressOfArg(2);
35 | t4 = gen->GetArgDWord(3);
36 | testVal = (t1 == 5) && (t2 == 9) && (t3 == 1) && (t4 == 3);
37 | }
38 |
39 | bool TestExecute4Args()
40 | {
41 | bool fail = false;
42 |
43 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
44 | if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
45 | engine->RegisterGlobalFunction("void cfunction(int, int16, int8, int)", asFUNCTION(cfunction_gen), asCALL_GENERIC);
46 | else
47 | engine->RegisterGlobalFunction("void cfunction(int, int16, int8, int)", asFUNCTION(cfunction), asCALL_CDECL);
48 |
49 | ExecuteString(engine, "cfunction(5, 9, 1, 3)");
50 |
51 | if( !called )
52 | {
53 | // failure
54 | PRINTF("\n%s: cfunction not called from script\n\n", TESTNAME);
55 | TEST_FAILED;
56 | }
57 | else if( !testVal )
58 | {
59 | // failure
60 | PRINTF("\n%s: testVal is not of expected value. Got (%d, %d, %d, %d), expected (%d, %d, %d, %d)\n\n", TESTNAME, t1, t2, t3, t4, 5, 9, 1, 3);
61 | TEST_FAILED;
62 | }
63 |
64 | engine->Release();
65 |
66 | // Success
67 | return fail;
68 | }
69 |
--------------------------------------------------------------------------------
/sdk/add_on/datetime/datetime.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTDATETIME_H
2 | #define SCRIPTDATETIME_H
3 |
4 | #ifndef ANGELSCRIPT_H
5 | // Avoid having to inform include path if header is already include before
6 | #include
7 | #endif
8 |
9 | #ifdef AS_CAN_USE_CPP11
10 | #include
11 | #else
12 | #error Sorry, this requires C++11 which your compiler doesnt appear to support
13 | #endif
14 |
15 | BEGIN_AS_NAMESPACE
16 |
17 | class CDateTime
18 | {
19 | public:
20 | // Constructors
21 | CDateTime();
22 | CDateTime(const CDateTime &other);
23 | CDateTime(asUINT year, asUINT month, asUINT day, asUINT hour, asUINT minute, asUINT second);
24 |
25 | // Copy the stored value from another any object
26 | CDateTime &operator=(const CDateTime &other);
27 |
28 | // Accessors
29 | asUINT getYear() const;
30 | asUINT getMonth() const;
31 | asUINT getDay() const;
32 | asUINT getHour() const;
33 | asUINT getMinute() const;
34 | asUINT getSecond() const;
35 | asUINT getWeekDay() const;
36 |
37 | // Setters
38 | // Returns true if valid
39 | bool setDate(asUINT year, asUINT month, asUINT day);
40 | bool setTime(asUINT hour, asUINT minute, asUINT second);
41 |
42 | // Operators
43 | // Return difference in seconds
44 | asINT64 operator-(const CDateTime &other) const;
45 | CDateTime operator+(asINT64 seconds) const;
46 | friend CDateTime operator+(asINT64 seconds, const CDateTime &other);
47 | CDateTime & operator+=(asINT64 seconds);
48 | CDateTime operator-(asINT64 seconds) const;
49 | friend CDateTime operator-(asINT64 seconds, const CDateTime &other);
50 | CDateTime & operator-=(asINT64 seconds);
51 | bool operator==(const CDateTime &other) const;
52 | bool operator<(const CDateTime &other) const;
53 |
54 | protected:
55 | std::chrono::system_clock::time_point tp;
56 | };
57 |
58 | void RegisterScriptDateTime(asIScriptEngine *engine);
59 |
60 | END_AS_NAMESPACE
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/sdk/tests/test_multithread/source/test_threadmgr.cpp:
--------------------------------------------------------------------------------
1 | // This test is to make sure it is possible to store the script engine in a global variable
2 | // that will be cleaned up only upon application exit. Previously this could cause the
3 | // application to crash when the library was built with multithreading, as the thread
4 | // manager was destroyed before the engine could clean up the global variables in the modules it held.
5 |
6 | #include "utils.h"
7 |
8 | namespace TestThreadMgr
9 | {
10 |
11 | // Compile a script that stores a global variable of a script class that has a destructor.
12 | // This will cause the destructor of the class to be called when the module is destroyed.
13 | static const char *script =
14 | "class MyTest \n"
15 | "{ \n"
16 | " MyTest() {var = 1;} \n"
17 | " ~MyTest() {var = 0;} \n"
18 | " int var; \n"
19 | "} \n"
20 | "MyTest global; \n";
21 |
22 | // Here's our global variable that will release the engine upon application exit
23 | class EngineWrapper
24 | {
25 | public:
26 | EngineWrapper() { engine = 0; }
27 | ~EngineWrapper() { if( engine ) engine->Release(); }
28 |
29 | asIScriptEngine *engine;
30 | } g_engine;
31 |
32 | bool Test()
33 | {
34 | bool fail = false;
35 |
36 | g_engine.engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
37 |
38 | COutStream out;
39 | g_engine.engine->SetMessageCallback(asMETHOD(COutStream,Callback),&out,asCALL_THISCALL);
40 |
41 | asIScriptModule *mod = g_engine.engine->GetModule(0, asGM_ALWAYS_CREATE);
42 | mod->AddScriptSection("script", script, strlen(script), 0);
43 | mod->Build();
44 |
45 | g_engine.engine->ClearMessageCallback();
46 |
47 | // Now the bomb has been armed. When the test application exits, if all goes
48 | // well the bomb should be disarmed correctly without crashing the application.
49 |
50 | // Success
51 | return fail;
52 | }
53 |
54 | } // namespace
55 |
56 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/test_parser.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | namespace TestParser
4 | {
5 |
6 | static const char * const TESTNAME = "TestParser";
7 |
8 | // Unfinished class
9 | const char *script1 =
10 | "class myclass \n"
11 | "{ \n";
12 |
13 | // Const with capital C
14 | const char *script2 =
15 | "class myclass \n"
16 | "{ \n"
17 | " void f(Const int&in) {} \n"
18 | "}; \n";
19 |
20 | bool Test()
21 | {
22 | bool fail = false;
23 | int r;
24 | asIScriptEngine *engine;
25 | CBufferedOutStream bout;
26 |
27 | // Test parser errors
28 | {
29 | engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
30 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
31 | bout.buffer = "";
32 |
33 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
34 | mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0);
35 | r = mod->Build();
36 | if (r >= 0)
37 | TEST_FAILED;
38 | if (bout.buffer != "TestParser (3, 1) : Error : Expected '}'\n"
39 | "TestParser (3, 1) : Error : Instead found ''\n")
40 | {
41 | PRINTF("%s", bout.buffer.c_str());
42 | TEST_FAILED;
43 | }
44 |
45 | bout.buffer = "";
46 | mod->AddScriptSection(TESTNAME, script2, strlen(script2), 0);
47 | r = mod->Build();
48 | if (r >= 0)
49 | TEST_FAILED;
50 | // TODO: The } token isn't unexpected, the parser is just not understanding that it is still inside the object declaration
51 | if (bout.buffer != "TestParser (3, 17) : Error : Expected ')' or ','\n"
52 | "TestParser (3, 17) : Error : Instead found reserved keyword 'int'\n"
53 | "TestParser (4, 1) : Error : Unexpected token '}'\n")
54 | {
55 | PRINTF("%s", bout.buffer.c_str());
56 | TEST_FAILED;
57 | }
58 |
59 | engine->Release();
60 | }
61 |
62 | // Success
63 | return fail;
64 | }
65 |
66 | } // namespace
67 |
68 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testexecute.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests calling of a c-function from a script
3 | //
4 | // Test author: Fredrik Ehnbom
5 | //
6 |
7 | #include "utils.h"
8 |
9 | static const char * const TESTNAME = "TestExecute";
10 |
11 | static bool called = false;
12 |
13 | static void cfunction() {
14 | called = true;
15 | }
16 |
17 | static void cfunction_generic(asIScriptGeneric *) {
18 | cfunction();
19 | }
20 |
21 | static void cleanContext(asIScriptContext *ctx)
22 | {
23 | assert(ctx->GetUserData() == (void*)(size_t)0xDEADF00D);
24 | called = true;
25 | }
26 |
27 | bool TestExecute()
28 | {
29 | bool fail = false;
30 |
31 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
32 | if( strstr(asGetLibraryOptions(),"AS_MAX_PORTABILITY") )
33 | {
34 | int r = engine->RegisterGlobalFunction("void cfunction()", asFUNCTION(cfunction_generic), asCALL_GENERIC); assert( r >= 0 );
35 | }
36 | else
37 | {
38 | int r = engine->RegisterGlobalFunction("void cfunction()", asFUNCTION(cfunction), asCALL_CDECL); assert( r >= 0 );
39 | }
40 | ExecuteString(engine, "cfunction()");
41 |
42 | if (!called) {
43 | PRINTF("\n%s: cfunction not called from script\n\n", TESTNAME);
44 | TEST_FAILED;
45 | }
46 |
47 |
48 | asIScriptContext *ctx = engine->CreateContext();
49 | void *p = ctx->SetUserData((void*)(size_t)0xDEADF00D); assert(p == 0);
50 | assert(ctx->GetUserData() == (void*)(size_t)0xDEADF00D);
51 | p = ctx->SetUserData(0); assert(p == (void*)(size_t)0xDEADF00D);
52 | p = ctx->SetUserData((void*)(size_t)0xDEADF00D); assert(p == 0);
53 | engine->SetContextUserDataCleanupCallback(cleanContext);
54 | called = false;
55 | // Prepare the context, but don't execute the function. The clean-up should work properly
56 | ctx->Prepare(engine->GetGlobalFunctionByDecl("void cfunction()"));
57 | ctx->Release();
58 | if( !called )
59 | TEST_FAILED;
60 |
61 | engine->Release();
62 | engine = NULL;
63 |
64 | return fail;
65 | }
66 |
--------------------------------------------------------------------------------
/sdk/tests/test_performance/projects/cmake/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4)
2 |
3 | project(test_performance)
4 |
5 | find_package(Threads)
6 |
7 | find_package(Angelscript CONFIG REQUIRED)
8 |
9 | add_executable(
10 | test_performance
11 | ../../source/main.cpp
12 | ../../source/scriptstring.cpp
13 | ../../source/test_assign.cpp
14 | ../../source/test_basic.cpp
15 | ../../source/test_basic2.cpp
16 | ../../source/test_call.cpp
17 | ../../source/test_call2.cpp
18 | ../../source/test_fib.cpp
19 | ../../source/test_int.cpp
20 | ../../source/test_intf.cpp
21 | ../../source/test_mthd.cpp
22 | ../../source/test_string.cpp
23 | ../../source/test_string2.cpp
24 | ../../source/test_string_pooled.cpp
25 | ../../source/test_thisprop.cpp
26 | ../../source/test_vector3.cpp
27 | ../../source/utils.cpp
28 | ../../../../add_on/debugger/debugger.cpp
29 | ../../../../add_on/scriptany/scriptany.cpp
30 | ../../../../add_on/scriptarray/scriptarray.cpp
31 | ../../../../add_on/scriptbuilder/scriptbuilder.cpp
32 | ../../../../add_on/scriptdictionary/scriptdictionary.cpp
33 | ../../../../add_on/scriptfile/scriptfile.cpp
34 | ../../../../add_on/scripthandle/scripthandle.cpp
35 | ../../../../add_on/scripthelper/scripthelper.cpp
36 | ../../../../add_on/scriptmath/scriptmath.cpp
37 | ../../../../add_on/scriptmath/scriptmathcomplex.cpp
38 | ../../../../add_on/scriptstdstring/scriptstdstring.cpp
39 | ../../../../add_on/scriptstdstring/scriptstdstring_utils.cpp
40 | ../../../../add_on/serializer/serializer.cpp
41 | )
42 | target_link_libraries(test_performance angelscript)
43 | set_target_properties(test_performance PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../bin)
44 | target_include_directories(test_performance PRIVATE angelscript)
45 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/test_discard.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests compiling a module and then discarding it
3 | //
4 | // Test author: Andreas Jonsson
5 | //
6 |
7 | #include "utils.h"
8 |
9 | namespace TestDiscard
10 | {
11 |
12 | static const char * const TESTNAME = "TestDiscard";
13 |
14 |
15 |
16 | static const char *script1 =
17 | "void Test() \n"
18 | "{ \n"
19 | " uint8[] kk(10); \n"
20 | " uint8[] kk2(10); \n"
21 | " func(kk, kk2, 10, 100); \n"
22 | "} \n";
23 |
24 |
25 | static void func(asIScriptGeneric *)
26 | {
27 | }
28 |
29 |
30 |
31 | bool Test()
32 | {
33 | bool fail = false;
34 | int r;
35 |
36 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
37 |
38 | COutStream out;
39 | engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
40 | RegisterScriptArray(engine, true);
41 | r = engine->RegisterGlobalFunction("uint8 func(uint8[] &in, uint8[] &inout, uint8, uint32)", asFUNCTION(func), asCALL_GENERIC); assert( r >= 0 );
42 |
43 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
44 | mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0);
45 | r = mod->Build();
46 | if( r < 0 ) TEST_FAILED;
47 |
48 | asIScriptContext *ctx = engine->CreateContext();
49 | ctx->Prepare(mod->GetFunctionByDecl("void Test()"));
50 | r = ctx->Execute();
51 | if( r != asEXECUTION_FINISHED )
52 | TEST_FAILED;
53 |
54 | // Prepare the context again, but don't execute it to see if the cleanup is proper
55 | ctx->Prepare(mod->GetFunctionByDecl("void Test()"));
56 | ctx->Release();
57 |
58 | engine->DiscardModule(0);
59 |
60 | mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
61 | mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0);
62 | r = mod->Build();
63 | if( r < 0 ) TEST_FAILED;
64 |
65 | engine->Release();
66 |
67 | // Success
68 | return fail;
69 | }
70 |
71 | } // namespace
72 |
73 |
74 |
--------------------------------------------------------------------------------
/sdk/docs/doxygen/source/doc_adv_dynamic_config.h:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | \page doc_adv_dynamic_config Dynamic configurations
4 |
5 | AngelScript supports the concept for configuration groups. This can be used for example by application plug-ins
6 | that wish to register their own interface with the script engine. When the plug-in is later removed, the configuration
7 | group for that plug-in can also be removed from the AngelScript interface without having to reinitialize everything.
8 |
9 | To register part of the interface in a configuration group, the registration should be done between calls to
10 | \ref asIScriptEngine::BeginConfigGroup "BeginConfigGroup" and \ref asIScriptEngine::EndConfigGroup "EndConfigGroup".
11 | This can be done as many times as desired, but groups cannot be nested. Observe that object methods, behaviours, and
12 | properties will always be placed in the same group where the object type was placed even if another group has been
13 | specified between the calls.
14 |
15 | To remove a configuration group the method \ref asIScriptEngine::RemoveConfigGroup "RemoveConfigGroup" should be called with the name given to the
16 | BeginConfigGroup. It is only possible to remove a config group that is not currently in use. Possible causes that
17 | prevents the removal of a group may be:
18 |
19 | - Another registered a function outside the group uses a type from the group
20 | - A script is currently built that uses a type or function from the group
21 | - An instance of a script object that uses a type or function from the group is alive
22 |
23 | It can be difficult to determine exactly where the use comes from so here's a few steps to do when RemoveConfigGroup
24 | returns \ref asCONFIG_GROUP_IS_IN_USE.
25 |
26 | - Run a full cycle on the \ref doc_gc "garbage collector" to destroy lingering objects
27 | - \ref asIScriptEngine::DiscardModule "Discard" any module that may have been compiled with the group
28 | - Double check that no other group uses the entities from the group
29 |
30 |
31 |
32 |
33 | */
34 |
--------------------------------------------------------------------------------
/sdk/add_on/scripthandle/scripthandle.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTHANDLE_H
2 | #define SCRIPTHANDLE_H
3 |
4 | #ifndef ANGELSCRIPT_H
5 | // Avoid having to inform include path if header is already include before
6 | #include
7 | #endif
8 |
9 |
10 | BEGIN_AS_NAMESPACE
11 |
12 | class CScriptHandle
13 | {
14 | public:
15 | // Constructors
16 | CScriptHandle();
17 | CScriptHandle(const CScriptHandle &other);
18 | CScriptHandle(void *ref, asITypeInfo *type);
19 | ~CScriptHandle();
20 |
21 | // Copy the stored value from another any object
22 | CScriptHandle &operator=(const CScriptHandle &other);
23 |
24 | // Set the reference
25 | void Set(void *ref, asITypeInfo *type);
26 |
27 | // Compare equalness
28 | bool operator==(const CScriptHandle &o) const;
29 | bool operator!=(const CScriptHandle &o) const;
30 | bool Equals(void *ref, int typeId) const;
31 |
32 | // Dynamic cast to desired handle type
33 | void Cast(void **outRef, int typeId);
34 |
35 | // Returns the type of the reference held
36 | asITypeInfo *GetType() const;
37 | int GetTypeId() const;
38 |
39 | // Get the reference
40 | void *GetRef();
41 |
42 | // GC callback
43 | void EnumReferences(asIScriptEngine *engine);
44 | void ReleaseReferences(asIScriptEngine *engine);
45 |
46 | protected:
47 | // These functions need to have access to protected
48 | // members in order to call them from the script engine
49 | friend void Construct(CScriptHandle *self, void *ref, int typeId);
50 | friend void RegisterScriptHandle_Native(asIScriptEngine *engine);
51 | friend void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen);
52 |
53 | void ReleaseHandle();
54 | void AddRefHandle();
55 |
56 | // These shouldn't be called directly by the
57 | // application as they requires an active context
58 | CScriptHandle(void *ref, int typeId);
59 | CScriptHandle &Assign(void *ref, int typeId);
60 |
61 | void *m_ref;
62 | asITypeInfo *m_type;
63 | };
64 |
65 | void RegisterScriptHandle(asIScriptEngine *engine);
66 |
67 | END_AS_NAMESPACE
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/test_argref.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | namespace TestArgRef
4 | {
5 |
6 | static const char * const TESTNAME = "TestArgRef";
7 |
8 |
9 |
10 | static const char *script1 =
11 | "int g; \n"
12 | "void TestArgRef() \n"
13 | "{ \n"
14 | " int a = 0; \n"
15 | " int[] b; \n"
16 | " Obj o; \n"
17 | " TestArgRef1(a); \n"
18 | " TestArgRef1(g); \n"
19 | " TestArgRef1(b[0]); \n"
20 | " TestArgRef1(o.v); \n"
21 | " string s; \n"
22 | " TestArgRef2(s); \n"
23 | "} \n"
24 | "void TestArgRef1(int &in arg) \n"
25 | "{ \n"
26 | "} \n"
27 | "void TestArgRef2(string &in str) \n"
28 | "{ \n"
29 | "} \n";
30 |
31 | struct Obj
32 | {
33 | int v;
34 | };
35 |
36 | bool Test()
37 | {
38 | bool fail = false;
39 | int r;
40 |
41 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
42 | RegisterScriptArray(engine, true);
43 | RegisterScriptString_Generic(engine);
44 |
45 | engine->RegisterObjectType("Obj", sizeof(Obj), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS);
46 | engine->RegisterObjectProperty("Obj", "int v", asOFFSET(Obj, v));
47 |
48 | COutStream out;
49 |
50 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
51 | mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0);
52 | engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
53 | r = mod->Build();
54 | if( r < 0 )
55 | {
56 | TEST_FAILED;
57 | PRINTF("%s: Failed to compile the script\n", TESTNAME);
58 | }
59 |
60 | engine->Release();
61 |
62 | // Success
63 | return fail;
64 | }
65 |
66 | } // namespace
67 |
68 |
--------------------------------------------------------------------------------
/sdk/tests/test_multithread/source/test_sharedstring.cpp:
--------------------------------------------------------------------------------
1 | // This test verifies that each thread has it's own shared string buffer
2 |
3 | #include "utils.h"
4 | #include
5 | #include
6 |
7 | namespace TestSharedString
8 | {
9 |
10 | #define TESTNAME "TestSharedString"
11 |
12 | static const char *script =
13 | "void TestSharedString1() \n"
14 | "{ \n"
15 | "} \n"
16 | "void TestSharedString2() \n"
17 | "{ \n"
18 | "} \n";
19 |
20 | static asIScriptEngine *engine = 0;
21 |
22 | void Thread(void *)
23 | {
24 | asIScriptModule *mod = engine->GetModule(0);
25 | asIScriptFunction *func = mod->GetFunctionByIndex(1);
26 | const char *str = func->GetDeclaration();
27 |
28 | // Give AngelScript a chance to cleanup some memory
29 | asThreadCleanup();
30 | }
31 |
32 | bool Test()
33 | {
34 | bool fail = false;
35 |
36 | engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
37 |
38 | COutStream out;
39 | engine->SetMessageCallback(asMETHOD(COutStream,Callback),&out,asCALL_THISCALL);
40 |
41 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
42 | mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
43 | mod->Build();
44 |
45 | // Get a function declaration, this should be the same after the other thread terminates
46 | asIScriptFunction *func = mod->GetFunctionByIndex(0);
47 | const char *str = func->GetDeclaration();
48 |
49 | // Create the second thread that in turn will get the declaration of another function
50 | HANDLE threadId = (HANDLE)_beginthread(Thread, 0, 0);
51 |
52 | // Make sure the other thread completes execution
53 | WaitForSingleObject(threadId, INFINITE);
54 |
55 | // Verify that the string we retrieved before is still the same
56 | if( strcmp(str, "void TestSharedString1()") != 0 )
57 | {
58 | printf("%s: Shared strings don't work as they should\n", TESTNAME);
59 | fail = true;
60 | }
61 |
62 | engine->Release();
63 |
64 | // Success
65 | return fail;
66 | }
67 |
68 | } // namespace
69 |
70 |
--------------------------------------------------------------------------------
/sdk/add_on/scriptany/scriptany.h:
--------------------------------------------------------------------------------
1 | #ifndef SCRIPTANY_H
2 | #define SCRIPTANY_H
3 |
4 | #ifndef ANGELSCRIPT_H
5 | // Avoid having to inform include path if header is already include before
6 | #include
7 | #endif
8 |
9 |
10 | BEGIN_AS_NAMESPACE
11 |
12 | class CScriptAny
13 | {
14 | public:
15 | // Constructors
16 | CScriptAny(asIScriptEngine *engine);
17 | CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine);
18 |
19 | // Memory management
20 | int AddRef() const;
21 | int Release() const;
22 |
23 | // Copy the stored value from another any object
24 | CScriptAny &operator=(const CScriptAny&);
25 | int CopyFrom(const CScriptAny *other);
26 |
27 | // Store the value, either as variable type, integer number, or real number
28 | void Store(void *ref, int refTypeId);
29 | void Store(asINT64 &value);
30 | void Store(double &value);
31 |
32 | // Retrieve the stored value, either as variable type, integer number, or real number
33 | bool Retrieve(void *ref, int refTypeId) const;
34 | bool Retrieve(asINT64 &value) const;
35 | bool Retrieve(double &value) const;
36 |
37 | // Get the type id of the stored value
38 | int GetTypeId() const;
39 |
40 | // GC methods
41 | int GetRefCount();
42 | void SetFlag();
43 | bool GetFlag();
44 | void EnumReferences(asIScriptEngine *engine);
45 | void ReleaseAllHandles(asIScriptEngine *engine);
46 |
47 | protected:
48 | virtual ~CScriptAny();
49 | void FreeObject();
50 |
51 | mutable int refCount;
52 | mutable bool gcFlag;
53 | asIScriptEngine *engine;
54 |
55 | // The structure for holding the values
56 | struct valueStruct
57 | {
58 | union
59 | {
60 | asINT64 valueInt;
61 | double valueFlt;
62 | void *valueObj;
63 | };
64 | int typeId;
65 | };
66 |
67 | valueStruct value;
68 | };
69 |
70 | void RegisterScriptAny(asIScriptEngine *engine);
71 | void RegisterScriptAny_Native(asIScriptEngine *engine);
72 | void RegisterScriptAny_Generic(asIScriptEngine *engine);
73 |
74 | END_AS_NAMESPACE
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/sdk/tests/test_feature/source/testint64.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Tests sending 8byte objects in a three levels deep function stack
3 | //
4 | // Sent in by: Adam Hoult (2004/07/02)
5 | //
6 |
7 | #include "utils.h"
8 |
9 | static const char * const TESTNAME = "TestInt64";
10 |
11 | static const char *script =
12 | "int Main()\n"
13 | "{\n"
14 | " // Call test\n"
15 | " foo();\n"
16 | " cfunction();\n"
17 | " Int64 var;\n"
18 | " bar( var );\n"
19 | " // Some value we'll know when we return\n"
20 | " return 31337;\n"
21 | "}\n"
22 |
23 | "void foo( )\n"
24 | "{\n"
25 | " Int64 var;\n"
26 | " bar( var );\n"
27 | "}\n"
28 |
29 | "void bar( Int64 )\n"
30 | "{\n"
31 | " cfunction();\n"
32 | "}\n";
33 |
34 | static int called = 0;
35 |
36 | static void cfunction(asIScriptGeneric *) {
37 | ++called;
38 | }
39 |
40 | bool TestInt64()
41 | {
42 | bool fail = false;
43 |
44 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
45 | engine->RegisterObjectType("Int64", 8, asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE);
46 | engine->RegisterGlobalFunction("void cfunction()", asFUNCTION(cfunction), asCALL_GENERIC);
47 |
48 | COutStream out;
49 | engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
50 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
51 | mod->AddScriptSection("test", script);
52 | mod->Build();
53 |
54 | asIScriptFunction *f = engine->GetModule(0)->GetFunctionByDecl("int Main()");
55 | asIScriptContext *ctx = engine->CreateContext();
56 | ctx->Prepare(f);
57 | int r = ctx->Execute();
58 | if( r != asEXECUTION_FINISHED )
59 | {
60 | PRINTF("\n%s: The execution didn't finish correctly (code %d)\n", TESTNAME, r);
61 | TEST_FAILED;
62 |
63 | if( r == asEXECUTION_EXCEPTION )
64 | PRINTF("%s", GetExceptionInfo(ctx).c_str());
65 | }
66 |
67 | if( called != 3 )
68 | {
69 | PRINTF("\n%s: cfunction called %d times. Expected 3 times\n", TESTNAME, called);
70 | TEST_FAILED;
71 | }
72 |
73 | ctx->Release();
74 | engine->Release();
75 |
76 | return fail;
77 | }
78 |
--------------------------------------------------------------------------------