CObject ExceptionObj() { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) ctx->SetException("application exception"); return CObject(); }
CObject SuspendObj() { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) ctx->Suspend(); return CObject(); }
bool aatc_script_Funcpointer::Set(aatc_type_string _funcname, void* ref, int tid){ funcname = _funcname; ready = 0; func = NULL; is_thiscall = 1; const char* funcname_c = funcname.c_str(); if (ref){ if ((tid & asTYPEID_MASK_OBJECT) && (tid & asTYPEID_OBJHANDLE)){//must be not primitive and a handle so = static_cast<asIScriptObject*>(*((void**)ref)); func = so->GetObjectType()->GetMethodByName(funcname_c); if (func){ ready = 1; } }else{//error asIScriptContext* ctx = asGetActiveContext(); engine = ctx->GetEngine(); char textbuf[1024]; sprintf_s(textbuf,1024, aatc_errormessage_funcpointer_nothandle,engine->GetObjectTypeById(tid)->GetName()); ctx->SetException(textbuf); } } return ready; }
CRefObject *ExceptionHandle() { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) ctx->SetException("application exception"); return 0; }
void aatc_script_Funcpointer::scriptsidecall_CallVoid(){ aatc_engine_level_storage* els = (aatc_engine_level_storage*)asGetActiveContext()->GetEngine()->GetUserData(aatc_engine_userdata_id); asIScriptContext* c = els->contextcache_Get(); Prepare(c); Execute(c); els->contextcache_Return(c); }
void ScriptAssert( const bool bCondition ) { if( bCondition ) return; std::cout << "Assertion failed: "; if( asIScriptContext* pContext = asGetActiveContext() ) { if( auto pFunction = pContext->GetFunction() ) { std::cout << "Section \"" << pFunction->GetScriptSectionName() << "\": " << pFunction->GetNamespace() << "::" << pFunction->GetName() << '('; std::cout << ')'; } else std::cout << "Unknown section and function"; int iColumn; const int iLineNumber = pContext->GetLineNumber( 0, &iColumn ); std::cout << std::endl << "Line " << iLineNumber << ", Column " << iColumn; } else std::cout << "Unknown condition"; std::cout << std::endl; }
void ExceptionHandle_gen(asIScriptGeneric *gen) { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) ctx->SetException("application exception"); gen->SetReturnObject(0); }
bool aatc_script_Funcpointer::Set(aatc_type_string _funcname){ asIScriptContext* ctx = asGetActiveContext(); engine = ctx->GetEngine(); funcname = _funcname; ready = 0; func = NULL; is_thiscall = 0; const char* funcname_c = funcname.c_str(); //application registered global functions func = engine->GetGlobalFunctionByDecl(funcname_c); //not found? script module global functions if (!func){ for (uint_fast32_t i = 0; i < engine->GetModuleCount(); i++){ func = engine->GetModuleByIndex(i)->GetFunctionByName(funcname_c); if (func){ break; } } } if (func){ ready = 1; } return ready; }
static CScriptArrayInterface *QAS_SplitString( const asstring_t &str, const asstring_t &delim ) { asIScriptContext *ctx = asGetActiveContext(); asIScriptEngine *engine = ctx->GetEngine(); asIObjectType *ot = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<String @>")); CScriptArrayInterface *arr = QAS_NEW(CScriptArray)(0, ot); const char *pdelim = delim.buffer; const size_t delim_len = strlen( pdelim ); const char *pbuf = str.buffer; const char *prev_pbuf = pbuf; // find all occurences of the delimiter in source string unsigned int count = 0; while( 1 ) { pbuf = strstr( prev_pbuf, pdelim ); if( !pbuf ) { break; } arr->Resize( count + 1 ); *((asstring_t **)arr->At(count)) = objectString_FactoryBuffer( prev_pbuf, pbuf - prev_pbuf ); prev_pbuf = pbuf + delim_len; count++; } // append the remaining part arr->Resize( count + 1 ); *((asstring_t **)arr->At(count)) = objectString_FactoryBuffer( prev_pbuf, strlen( prev_pbuf ) ); return arr; }
Context::Ptr Context::activeContext() { asIScriptContext *ctx = asGetActiveContext(); if (!ctx) return NULL; return new Context(ctx, true); }
static uint64_t GetSolidBits(int x, int y, VoxelModel *m) { if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight()) { asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range."); return 0; } return m->GetSolidBitsAt(x, y); }
void SuspendObj_gen(asIScriptGeneric*gen) { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) ctx->Suspend(); CObject obj; gen->SetReturnObject(&obj); }
void aatc_errorprint_container_access_empty(const char* name_container, const char* name_content, const char* name_operation){ #if aatc_CONFIG_ENABLE_ERRORCHECK_RUNTIME_EXCEPTIONS char msg[1000]; //sprintf_s(msg, 1000, aatc_errormessage_container_missing_method_formatting, name_content, name_container, name_operation); sprintf_s(msg, 1000, aatc_errormessage_container_access_empty_formatting, aatc_errormessage_container_access_empty_formatting_param1, aatc_errormessage_container_access_empty_formatting_param2, aatc_errormessage_container_access_empty_formatting_param3); asGetActiveContext()->SetException(msg); #endif }
static void SetSolid(int x, int y, int z, uint32_t col, VoxelModel *m) { if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() || z < 0 || z >= m->GetDepth()) { asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range."); return; } m->SetSolid(x, y, z, col); }
/************************************************************************ * desc: Suspend the script to the game loop ************************************************************************/ void Suspend() { asIScriptContext *ctx = asGetActiveContext(); // Suspend the context so the game loop can resumed if( ctx ) ctx->Suspend(); } // Suspend
static CASPluginData* Plugin_GetPluginData() { auto pModule = GetModuleFromScriptContext( asGetActiveContext() ); if( !pModule ) return nullptr; return CASModule_GetPluginData( pModule ); }
static std::string CPluginData_GetName( const CASPluginData* /*pThis*/ ) { auto pScriptModule = GetScriptModuleFromScriptContext( asGetActiveContext() ); if( !pScriptModule ) return "<Unknown>"; return pScriptModule->GetName(); }
static bool IsSolid(int x, int y, int z, VoxelModel *m) { if(x < 0 || y < 0 || x >= m->GetWidth() || y >= m->GetHeight() || z < 0 || z >= m->GetDepth()) { asGetActiveContext()->SetException("Attempted to access a voxel outside the valid range."); return 0; } return m->IsSolid(x, y, z); }
int *Point_Index(Point &point, int iIndex) { if ((iIndex < 0) || (iIndex > 1)) asGetActiveContext()->SetException("Point index out of range."); if (iIndex == 0) return &point.x; else return &point.y; }
ScriptFile* GetScriptContextFile() { asIScriptContext* context = asGetActiveContext(); asIScriptFunction* function = context ? context->GetFunction() : 0; asIScriptModule* module = function ? function->GetEngine()->GetModule(function->GetModuleName()) : 0; if (module) return static_cast<ScriptFile*>(module->GetUserData()); else return 0; }
void DebugCall() { asIScriptContext *ctx = asGetActiveContext(); // Get the address of the output parameter void *varPointer = ctx->GetAddressOfVar(0, 0); // We got the address to the reference to the handle CScriptString **str = *(CScriptString***)varPointer; // Set the handle to point to a new string *str = new CScriptString("test"); }
aatc_DATAHANDLINGTYPE aatc_Determine_Datahandlingtype(aatc_type_uint32 astypeid){ if(astypeid == asGetActiveContext()->GetEngine()->GetStringFactoryReturnTypeId()){ return aatc_DATAHANDLINGTYPE::STRING; } if(astypeid & asTYPEID_MASK_OBJECT){ if(astypeid & asTYPEID_OBJHANDLE){ return aatc_DATAHANDLINGTYPE::HANDLE; } else{ return aatc_DATAHANDLINGTYPE::OBJECT; } } else{ return aatc_DATAHANDLINGTYPE::PRIMITIVE; } }
static void Assert(bool expr) { if( !expr ) { printf("Assert failed\n"); asIScriptContext *ctx = asGetActiveContext(); if( ctx ) { asIScriptEngine *engine = ctx->GetEngine(); printf("func: %s\n", engine->GetFunctionDeclaration(ctx->GetCurrentFunction())); printf("line: %d\n", ctx->GetCurrentLineNumber()); ctx->SetException("Assert failed"); } } }
CScriptArray *CreateArrayOfStrings() { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) { asIScriptEngine* engine = ctx->GetEngine(); asIObjectType* t = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string@>")); CScriptArray* arr = new CScriptArray(3, t); for( asUINT i = 0; i < arr->GetSize(); i++ ) { CScriptString** p = static_cast<CScriptString**>(arr->At(i)); *p = new CScriptString("test"); } return arr; } return 0; }
void CheckFunc(asIScriptGeneric *) { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) { const asIScriptFunction *func = ctx->GetFunction(); if( strcmp(func->GetModuleName(), "DynamicModule") != 0 ) failed = true; if( strcmp(func->GetDeclaration(), "void Test()") != 0 ) failed = true; ctx->SetException("Generated exception"); } else failed = true; }
void DebugCall() { asIScriptContext *ctx = asGetActiveContext(); // Get the address of the output parameter void *varPointer = ctx->GetAddressOfVar(0, 0); // We got the address to the handle CScriptString **str = (CScriptString**)varPointer; // Set the handle to point to a new string *str = new CScriptString("test"); // It is possible to determine the function that is being called too asIScriptFunction *func = ctx->GetSystemFunction(); assert( std::string(func->GetDeclaration()) == "void debugCall()" ); }
void CheckFunc() { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) { asIScriptEngine *engine = ctx->GetEngine(); int funcID = ctx->GetCurrentFunction(); if( strcmp(engine->GetFunctionModule(funcID), "DynamicModule") != 0 ) failed = true; if( strcmp(engine->GetFunctionDeclaration(funcID), "void Test()") != 0 ) failed = true; ctx->SetException("Generated exception"); } else failed = true; }
void CheckFunc(asIScriptGeneric *) { asIScriptContext *ctx = asGetActiveContext(); if( ctx ) { asIScriptEngine *engine = ctx->GetEngine(); int funcID = ctx->GetCurrentFunction(); const asIScriptFunction *func = engine->GetFunctionDescriptorById(funcID); if( strcmp(func->GetModuleName(), "DynamicModule") != 0 ) failed = true; if( strcmp(func->GetDeclaration(), "void Test()") != 0 ) failed = true; ctx->SetException("Generated exception"); } else failed = true; }
asBYTE *asBStrByteAt(int index, const asBSTR *s) { if( index < 0 || index >= (signed)asBStrLength(*s) ) { // The script is trying to access memory that isn't // allowed so we'll throw an exception. asIScriptContext *context = asGetActiveContext(); // Should this function be called by the host application directly // then there will not be any active context to set the exception on if( context ) context->SetException("Out of range"); // Don't return any objects to the script engine after // setting an exception as they will not be released return 0; } return *s + index; }
// This function takes an input string and splits it into parts by looking // for a specified delimiter. Example: // // string str = "A|B||D"; // array<string@>@ array = split(str, "|"); // // The resulting array has the following elements: // // {"A", "B", "", "D"} // // AngelScript signature: // array<string@>@ split(const string &in str, const string &in delim) void StringSplit_Generic(asIScriptGeneric *gen) { // Obtain a pointer to the engine asIScriptContext *ctx = asGetActiveContext(); asIScriptEngine *engine = ctx->GetEngine(); // TODO: This should only be done once // TODO: This assumes that CScriptArray was already registered asIObjectType *arrayType = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string@>")); // Create the array object CScriptArray *array = new CScriptArray(0, arrayType); // Get the arguments CScriptString *str = *(CScriptString**)gen->GetAddressOfArg(0); CScriptString *delim = *(CScriptString**)gen->GetAddressOfArg(1); // Find the existence of the delimiter in the input string int pos = 0, prev = 0, count = 0; while( (pos = (int)str->buffer.find(delim->buffer, prev)) != (int)std::string::npos ) { // Add the part to the array CScriptString *part = new CScriptString(); part->buffer.assign(&str->buffer[prev], pos-prev); array->Resize(array->GetSize()+1); *(CScriptString**)array->At(count) = part; // Find the next part count++; prev = pos + (int)delim->buffer.length(); } // Add the remaining part CScriptString *part = new CScriptString(); part->buffer.assign(&str->buffer[prev]); array->Resize(array->GetSize()+1); *(CScriptString**)array->At(count) = part; // Return the array by handle *(CScriptArray**)gen->GetAddressOfReturnLocation() = array; }