These are a few tips and tricks that may come in handy.
The line callback feature is used to be able to some special treatment during execution of the scripts. The callback is called for every script statement, which for example makes it possible to verify if the script has executed for too long time and if so suspend the execution to be resumed at a later time.
Before calling the context's Execute() method, set the callback function like so:
void ExecuteScript() { DWORD timeOut; ctx->SetLineCallback(asFUNCTION(LineCallback), &timeOut, asCALL_CDECL); int status = asEXECUTION_SUSPENDED; while( status == asEXECUTION_SUSPENDED ) { // Allow the long running script to execute for 10ms timeOut = timeGetTime() + 10; status = ctx->Execute(); // The execution was suspended, now we can do something else before // continuing the execution with another call to Execute(). ... } } void LineCallback(asIScriptContext *ctx, DWORD *timeOut) { // If the time out is reached we suspend the script if( *timeOut < timeGetTime() ) ctx->Suspend(); }
Take a look at the sample events to see this working.
AngelScript is written with C++, and unfortunately C++ compilers were never standardized on the binary level, so code compiled by one C++ compiler is usually not compatible with code compiled from another C++ compiler.
Fortunately there is a way to make a binary compatible DLL of AngelScript. Because of the large base of ANSI C resources readily available all C++ compilers make sure to produce compatible C code. Even other languages, such as Delphi and D, are able to use an ANSI C compatible dll. AngelScript has a prepared C compatible interface that can be used for this purpose.
To compile the dll and expose the C interface some preprocessor flags has
to be turned on: AS_C_INTERFACE
and ANGELSCRIPT_EXPORT
.
Obviously it will not be possible to register C++ class methods through this
interface, so it might be useful to remove that part from the engine by
defining the flag AS_NO_CLASS_METHODS
.
These flags and others are documented in the as_config.h header file.