MCPcopy Create free account
hub / github.com/anjo76/angelscript / Test2Modules

Function Test2Modules

sdk/tests/test_feature/source/test2modules.cpp:12–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10static const char *script = "int global; void Test() {global = 0;} float Test2() {Test(); return 0;}";
11
12bool Test2Modules()
13{
14 bool fail = false;
15 int r;
16
17 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
18
19 asIScriptModule *mod = engine->GetModule("a", asGM_ALWAYS_CREATE);
20 mod->AddScriptSection("script", script, strlen(script), 0);
21 if( mod->Build() < 0 )
22 {
23 PRINTF("%s: failed to build module a\n", TESTNAME);
24 TEST_FAILED;
25 }
26
27 mod = engine->GetModule("b", asGM_ALWAYS_CREATE);
28 mod->AddScriptSection("script", script, strlen(script), 0);
29 if( mod->Build() < 0 )
30 {
31 PRINTF("%s: failed to build module b\n", TESTNAME);
32 TEST_FAILED;
33 }
34
35 if( !fail )
36 {
37 asIScriptFunction *aFunc = engine->GetModule("a")->GetFunctionByName("Test");
38 if( aFunc == 0 )
39 {
40 PRINTF("%s: failed to retrieve func ID for module a\n", TESTNAME);
41 TEST_FAILED;
42 }
43
44 asIScriptFunction *bFunc = engine->GetModule("b")->GetFunctionByName("Test");
45 if( bFunc == 0 )
46 {
47 PRINTF("%s: failed to retrieve func ID for module b\n", TESTNAME);
48 TEST_FAILED;
49 }
50 }
51
52 engine->Release();
53
54 // Test using an object created in another module
55 engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
56 engine->RegisterInterface("ITest");
57 engine->RegisterInterfaceMethod("ITest", "void test()");
58 const char *scriptA = "ITest @obj;";
59 const char *scriptB =
60 "class CTest : ITest \n"
61 "{ \n"
62 " void test() {glob = 42;} \n"
63 "} \n"
64 "int glob = 0; \n";
65
66 mod = engine->GetModule("a", asGM_ALWAYS_CREATE);
67 mod->AddScriptSection("scriptA", scriptA, strlen(scriptA));
68 r = mod->Build();
69 if( r < 0 ) TEST_FAILED;

Callers 1

allTestsFunction · 0.85

Calls 12

ExecuteStringFunction · 0.85
AddScriptSectionMethod · 0.80
GetFunctionByNameMethod · 0.80
CreateScriptObjectMethod · 0.80
GetAddressOfGlobalVarMethod · 0.80
GetModuleMethod · 0.45
BuildMethod · 0.45
ReleaseMethod · 0.45
RegisterInterfaceMethod · 0.45
GetTypeInfoByNameMethod · 0.45

Tested by

no test coverage detected