zerochen

Members
  • Content count

    12
  • Joined

  • Last visited

Community Reputation

542 Good

About zerochen

  • Rank
    Member
  1. Request for adding buffer pointer getter to script array

    hi, i also would love to see a getter for the scripthandle addon, so that i can access the internal pointer and can do stuff with it. thanks in advance
  2. AngelScript 2.27.1 is here (so soon? yes)

    Hi,   what are the next big features / addons / updates that you will add?
  3. constructor + templates => constructor isnt called

    hi, i finally found the problem. the problem was that i register the default constructor for the vector and the matrix with the same functionname in different source files. so the defaullt constructor of the maxtrix overrides the vectors default constructor because they have the same structure & name. thanks anyway
  4. constructor + templates => constructor isnt called

    hi, i use visual studio 2012, the lastest angelscript rev and win 7 64bit. i also noticed that this only happens with the default constructor (no arguments are passed). for other methods and behaviours it works.
  5. hi, i have a problem with the constructor and templates. if i register my vector class with constructorDefault<T> it doesnt work because the constructorDefault function is never been called. only then i use the constructorDefaultf function it works. is there something i missed? C++: [CODE]template<typename T> void constructorDefault(void *memory) // this isnt called { new (memory) core::vector3d<T>(); } void constructorDefaultf(void *memory) // works fine { new (memory) core::vector3d<float>(); } template<typename T> void deconstructor(void *memory) { ((core::vector3d<T>*)memory)->~vector3d<T>(); } // called like that -> registerVector3dT<float>(engine, "vector3df", "float"); template<typename T> void registerVector3dT(asIScriptEngine *engine, const char *typeName, const char *asType) { int r; std::stringstream ss; // Bind Vector2d<T> class. r = engine->RegisterObjectType(typeName, sizeof(core::vector3d<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); assert(r >= 0); //this doesnt work r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructorDefault<T>, (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0); // this works //r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructorDefaultf, (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTIONPR(deconstructor<T>, (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0); // Assignment vector3d<T>& operator=(const vector3d<T>& other) ss.str(""); ss << typeName << "& opAssign(const " << typeName << " &in)"; r = engine->RegisterObjectMethod(typeName, ss.str().c_str(), asMETHODPR(core::vector3d<T>, operator=, (const core::vector3d<T>&), core::vector3d<T>&), asCALL_THISCALL); assert(r >= 0); // Bind core::vector3d<T> class properties. ss.str(""); ss << asType << " X"; r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(core::vector3d<T>, X)); assert(r >= 0); ss.str(""); ss << asType << " Y"; r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(core::vector3d<T>, Y)); assert(r >= 0); ss.str(""); ss << asType << " Z"; r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(core::vector3d<T>, Z)); assert(r >= 0); } [/CODE] Angelscript: [CODE] class d { void dummy() { vector3df ss(); vector3df sss(); sss = ss; } } [/CODE] in that line it crashed: void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i, asCScriptFunction *s) line 3394: (((asCSimpleDummy*)obj)->*f)(); callstack: game.exe![thunk]:asCScriptObject::`vcall'{4,{flat}}' }'() C++ game.exe!asCScriptEngine::CallObjectMethod(void * obj, asSSystemFunctionInterface * i, asCScriptFunction * s) Zeile 3413 C++ game.exe!asCScriptEngine::CallObjectMethod(void * obj, int func) Zeile 3367 C++ game.exe!asCContext::ExecuteNext() Zeile 2503 C++ game.exe!asCContext::Execute() Zeile 1155 C++ i guess it crashs there because the constructor isnt called. any help would be appreciated thx
  6. Hi, this code leads to a wrong error msg. [CODE] void dum() {} int dummy() { return 0; dum(); //return 1; } [/CODE] output: player.as (35, 2) : INFO : Compiling int CPlayer::dummy() player.as (38, 3) : WARN : Unreachable code player.as (36, 2) : ERR : Not all paths return a value If you uncomment the last line it works. it works also with an int a; instead of a func call
  7. hi, i wrote a patch for this some time ago [CODE] Index: include/angelscript.h =================================================================== --- include/angelscript.h (Revision 1359) +++ include/angelscript.h (Arbeitskopie) @@ -520,6 +520,7 @@ virtual asIJITCompiler *GetJITCompiler() const = 0; // Global functions + virtual int RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv) = 0; virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0; virtual asUINT GetGlobalFunctionCount() const = 0; #ifdef AS_DEPRECATED Index: source/as_callfunc.cpp =================================================================== --- source/as_callfunc.cpp (Revision 1359) +++ source/as_callfunc.cpp (Arbeitskopie) @@ -409,12 +409,8 @@ if( callConv >= ICC_THISCALL ) { - if( objectPointer ) + if(!((obj = objectPointer) || (obj = descr->GetUserData()))) { - obj = objectPointer; - } - else - { // The object pointer should be popped from the context stack popSize += AS_PTR_SIZE; Index: source/as_scriptengine.cpp =================================================================== --- source/as_scriptengine.cpp (Revision 1359) +++ source/as_scriptengine.cpp (Arbeitskopie) @@ -2458,6 +2458,83 @@ } // interface +int asCScriptEngine::RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv) +{ + asSSystemFunctionInterface internal; + + int r = DetectCallingConvention(true, funcPointer, callConv, &internal); + if( r < 0 ) + return ConfigError(r, "RegisterGlobalFunction", declaration, 0); + + if( callConv != asCALL_THISCALL) + return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); + + isPrepared = false; + + // Put the system function in the list of system functions + asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal); + + if( newInterface == 0 ) + return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); + + asCScriptFunction *func = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM); + + if( func == 0 ) + { + asDELETE(newInterface, asSSystemFunctionInterface); + return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); + } + + func->sysFuncIntf = newInterface; + func->SetUserData(obj); + + asCBuilder bld(this, 0); + r = bld.ParseFunctionDeclaration(0, declaration, func, true, &newInterface->paramAutoHandles, &newInterface->returnAutoHandle, defaultNamespace); + if( r < 0 ) + { + // Set as dummy function before deleting + func->funcType = asFUNC_DUMMY; + asDELETE(func,asCScriptFunction); + return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0); + } + + // TODO: namespace: What if the declaration defined an explicit namespace? + func->nameSpace = defaultNamespace; + + // Check name conflicts + r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, defaultNamespace); + if( r < 0 ) + { + asDELETE(func,asCScriptFunction); + return ConfigError(asNAME_TAKEN, "RegisterGlobalFunction", declaration, 0); + } + + func->id = GetNextScriptFunctionId(); + SetScriptFunction(func); + + currentGroup->scriptFunctions.PushLast(func); + func->accessMask = defaultAccessMask; + registeredGlobalFuncs.PushLast(func); + + // If parameter type from other groups are used, add references + if( func->returnType.GetObjectType() ) + { + asCConfigGroup *group = FindConfigGroupForObjectType(func->returnType.GetObjectType()); + currentGroup->RefConfigGroup(group); + } + for( asUINT n = 0; n < func->parameterTypes.GetLength(); n++ ) + { + if( func->parameterTypes[n].GetObjectType() ) + { + asCConfigGroup *group = FindConfigGroupForObjectType(func->parameterTypes[n].GetObjectType()); + currentGroup->RefConfigGroup(group); + } + } + + // Return the function id as success + return func->id; +} + int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) { asSSystemFunctionInterface internal; Index: source/as_scriptengine.h =================================================================== --- source/as_scriptengine.h (Revision 1359) +++ source/as_scriptengine.h (Arbeitskopie) @@ -100,6 +100,7 @@ virtual asIJITCompiler *GetJITCompiler() const; // Global functions + virtual int RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv); virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv); virtual asUINT GetGlobalFunctionCount() const; #ifdef AS_DEPRECATED [/CODE] example usage: engine->RegisterGlobalFunction("void Println(const string& in)", asMETHODPR(CScriptFunction, println, (const std::string&), void), this /*pointer to obj of CScriptFunction*/, asCALL_THISCALL);
  8. ref count fails

    ok thx that solved the problem. i thought it was because the createScriptObject func returns sometimes an obj with ref count 2
  9. ref count fails

    [CODE] // this function is called from angelscript CScriptHandle CScriptFunction::createObject(const std::string& name, const core::vector3df& pos) { int id = builder.GetModule()->GetTypeIdByDecl(name.c_str()); if(id == asINVALID_TYPE) { //error msg return CScriptHandle(); } asIScriptObject* s = reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(id)); //here the ref count is sometimes 2 if(!scriptObj) return CScriptHandle(); // set pos // add it to an objArray return CScriptHandle(scriptObj, scriptObj->GetObjectType()); } [/CODE] [quote]// The CScriptHandle increased the ref count when it // stored the handle internally so we need to release one[/quote] yes but if the CScriptHandle will be destroyed the ref counter will dec but the problem is direct after the engine createObject function so i think it is a angelscript problem i will write a little example that reproduce the problem but now i have no time sry
  10. ref count fails

    with angelscript in c++ yes [CODE] CScriptHandle CScriptFunction::createObject(const std::string& name, const core::vector3df& pos) r = script->getEngine()->RegisterGlobalFunction("ref@ CreateObject(const string& in, const vector3df& in)", asMETHODPR(CScriptFunction, createObject, (const std::string&, const core::vector3df&), CScriptHandle), this, asCALL_THISCALL); assert( r >= 0 ); [/CODE] i wrote a patch for angelscript that allows me to register a global script function as a method of a class. maybe thats the problem but i use it for weeks without any problems. i think it is the nested context here is the patch file. [CODE] Index: include/angelscript.h =================================================================== --- include/angelscript.h (Revision 1359) +++ include/angelscript.h (Arbeitskopie) @@ -520,6 +520,7 @@ virtual asIJITCompiler *GetJITCompiler() const = 0; // Global functions + virtual int RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv) = 0; virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0; virtual asUINT GetGlobalFunctionCount() const = 0; #ifdef AS_DEPRECATED Index: source/as_callfunc.cpp =================================================================== --- source/as_callfunc.cpp (Revision 1359) +++ source/as_callfunc.cpp (Arbeitskopie) @@ -409,12 +409,8 @@ if( callConv >= ICC_THISCALL ) { - if( objectPointer ) + if(!((obj = objectPointer) || (obj = descr->GetUserData()))) { - obj = objectPointer; - } - else - { // The object pointer should be popped from the context stack popSize += AS_PTR_SIZE; Index: source/as_scriptengine.cpp =================================================================== --- source/as_scriptengine.cpp (Revision 1359) +++ source/as_scriptengine.cpp (Arbeitskopie) @@ -2458,6 +2458,83 @@ } // interface +int asCScriptEngine::RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv) +{ + asSSystemFunctionInterface internal; + + int r = DetectCallingConvention(true, funcPointer, callConv, &internal); + if( r < 0 ) + return ConfigError(r, "RegisterGlobalFunction", declaration, 0); + + if( callConv != asCALL_THISCALL) + return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); + + isPrepared = false; + + // Put the system function in the list of system functions + asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal); + + if( newInterface == 0 ) + return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); + + asCScriptFunction *func = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM); + + if( func == 0 ) + { + asDELETE(newInterface, asSSystemFunctionInterface); + return ConfigError(asOUT_OF_MEMORY, "RegisterGlobalFunction", declaration, 0); + } + + func->sysFuncIntf = newInterface; + func->SetUserData(obj); + + asCBuilder bld(this, 0); + r = bld.ParseFunctionDeclaration(0, declaration, func, true, &newInterface->paramAutoHandles, &newInterface->returnAutoHandle, defaultNamespace); + if( r < 0 ) + { + // Set as dummy function before deleting + func->funcType = asFUNC_DUMMY; + asDELETE(func,asCScriptFunction); + return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0); + } + + // TODO: namespace: What if the declaration defined an explicit namespace? + func->nameSpace = defaultNamespace; + + // Check name conflicts + r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, defaultNamespace); + if( r < 0 ) + { + asDELETE(func,asCScriptFunction); + return ConfigError(asNAME_TAKEN, "RegisterGlobalFunction", declaration, 0); + } + + func->id = GetNextScriptFunctionId(); + SetScriptFunction(func); + + currentGroup->scriptFunctions.PushLast(func); + func->accessMask = defaultAccessMask; + registeredGlobalFuncs.PushLast(func); + + // If parameter type from other groups are used, add references + if( func->returnType.GetObjectType() ) + { + asCConfigGroup *group = FindConfigGroupForObjectType(func->returnType.GetObjectType()); + currentGroup->RefConfigGroup(group); + } + for( asUINT n = 0; n < func->parameterTypes.GetLength(); n++ ) + { + if( func->parameterTypes[n].GetObjectType() ) + { + asCConfigGroup *group = FindConfigGroupForObjectType(func->parameterTypes[n].GetObjectType()); + currentGroup->RefConfigGroup(group); + } + } + + // Return the function id as success + return func->id; +} + int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) { asSSystemFunctionInterface internal; Index: source/as_scriptengine.h =================================================================== --- source/as_scriptengine.h (Revision 1359) +++ source/as_scriptengine.h (Arbeitskopie) @@ -100,6 +100,7 @@ virtual asIJITCompiler *GetJITCompiler() const; // Global functions + virtual int RegisterGlobalFunction(const char* declaration, const asSFuncPtr &funcPointer, void* obj, asDWORD callConv); virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv); virtual asUINT GetGlobalFunctionCount() const; #ifdef AS_DEPRECATED [/CODE] i just copied the RegisterGlobalFunction, added the void* obj pointer to the function and set it after func->sysFuncIntf = newInterface; + func->SetUserData(obj); ah i use the lastest angelscript svn version of couse
  11. ref count fails

    hi, i have following base structure Script: [CODE] class A { }; class B { void init() { create("A"); }; }; [/CODE] pseudo c++: [CODE] asIScriptObject* create(string s) { int id = getClassId(s); return reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(id)); } [/CODE] so now to my problem. i create class B and than i call the function init() from B that creates a new object from A something like this: pseudo call stack: [CODE] objB = create("B") objB.callMethod("init") that calls objA = create("A") [/CODE] after that the ref count of objB is 1 (as expected) the ref count of objA is 2 (have to be 1) have i an error in my logic? i tracked this down to: as_scriptobject.cpp line 122 that line doesnt dec the ref counter of objA but it does it for objB. is that because to call a script function there has to be an active context? is this a bug or have i call the release func myself? thx for help zerochen
  12. switch return bug

    hi, i think i found a bug with a switch and return statements asscript: [source lang="cpp"] bool onEvent() { switch(1) { case 1: return true; default: return false; } }[/source] error: objects/Controller.as (54, 2) : INFO : Compiling bool Controller::onEvent() objects/Controller.as (55, 2) : ERR : Not all paths return a value but that isnt true. maybe return statements are not supported in switch cases. if so this is a feature request:) thx