1 module as.context; 2 import as.def; 3 import as.engine; 4 import as.func; 5 6 class ScriptContext { 7 private: 8 ScriptEngine engine; 9 10 ~this() { 11 // Make sure we don't try to destroy the engine 12 this.engine = null; 13 14 // Release the context 15 asContext_Release(ctx); 16 } 17 18 package(as): 19 asIScriptContext* ctx; 20 21 this(ScriptEngine engine, asIScriptContext* ctx) { 22 this.engine = engine; 23 this.ctx = ctx; 24 } 25 26 public: 27 /** 28 Adds a reference to this script context 29 */ 30 int addRef() { 31 return asContext_AddRef(ctx); 32 } 33 34 /** 35 Releases a reference to this script context 36 */ 37 int release() { 38 return asContext_Release(ctx); 39 } 40 41 /** 42 Gets the script engine this context belongs to 43 */ 44 ScriptEngine getEngine() { 45 return engine; 46 } 47 48 /** 49 Prepares this context 50 */ 51 void prepare(Function func) { 52 asContext_Prepare(ctx, func.func); 53 } 54 55 /** 56 Un-prepares this context 57 */ 58 void unprepare() { 59 asContext_Unprepare(ctx); 60 } 61 62 /** 63 Executes this context 64 */ 65 void execute() { 66 asContext_Execute(ctx); 67 } 68 69 /** 70 Aborts this context 71 */ 72 void abort() { 73 asContext_Abort(ctx); 74 } 75 76 /** 77 Suspends this context 78 */ 79 void suspend() { 80 asContext_Suspend(ctx); 81 } 82 83 /** 84 Gets the current state of the context 85 */ 86 asEContextState getState() { 87 return asContext_GetState(ctx); 88 } 89 90 void pushState() { 91 asContext_PushState(ctx); 92 } 93 94 void popState() { 95 asContext_PopState(ctx); 96 } 97 98 bool isNested(ref uint nestCount) { 99 return asContext_IsNested(ctx, &nestCount); 100 } 101 102 void setObject(void* obj) { 103 asContext_SetObject(ctx, obj); 104 } 105 106 void* setUserData(void* data) { 107 return asContext_SetUserData(ctx, data); 108 } 109 110 void* getUserData() { 111 return asContext_GetUserData(ctx); 112 } 113 }