| 194 | } |
| 195 | |
| 196 | int CompileScript(asIScriptEngine *engine) |
| 197 | { |
| 198 | int r; |
| 199 | |
| 200 | // This script prints a message 3 times per second |
| 201 | const char *script1 = |
| 202 | "int count = 0; " |
| 203 | "void main() " |
| 204 | "{ " |
| 205 | " for(;;) " |
| 206 | " { " |
| 207 | " Print(\"A :\"); " |
| 208 | " Print(count++); " |
| 209 | " Print(\"\\n\"); " |
| 210 | " sleep(333); " |
| 211 | " } " |
| 212 | "} "; |
| 213 | |
| 214 | // This script prints a message once per second |
| 215 | const char *script2 = |
| 216 | "int count = 0; " |
| 217 | "void main() " |
| 218 | "{ " |
| 219 | " for(;;) " |
| 220 | " { " |
| 221 | " Print(\" B:\"); " |
| 222 | " Print(count++); " |
| 223 | " Print(\"\\n\"); " |
| 224 | " sleep(1000); " |
| 225 | " } " |
| 226 | "} "; |
| 227 | |
| 228 | // Build the two script into separate modules. This will make them have |
| 229 | // separate namespaces, which allows them to use the same name for functions |
| 230 | // and global variables. |
| 231 | asIScriptModule *mod = engine->GetModule("script1", asGM_ALWAYS_CREATE); |
| 232 | r = mod->AddScriptSection("script1", script1, strlen(script1)); |
| 233 | if( r < 0 ) |
| 234 | { |
| 235 | cout << "AddScriptSection() failed" << endl; |
| 236 | return -1; |
| 237 | } |
| 238 | |
| 239 | r = mod->Build(); |
| 240 | if( r < 0 ) |
| 241 | { |
| 242 | cout << "Build() failed" << endl; |
| 243 | return -1; |
| 244 | } |
| 245 | |
| 246 | mod = engine->GetModule("script2", asGM_ALWAYS_CREATE); |
| 247 | r = mod->AddScriptSection("script2", script2, strlen(script2)); |
| 248 | if( r < 0 ) |
| 249 | { |
| 250 | cout << "AddScriptSection() failed" << endl; |
| 251 | return -1; |
| 252 | } |
| 253 |
no test coverage detected