• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

120 Neutral

About ASBai

  • Rank

Personal Information

  • Interests
  1. Can not create a value type template

    Got it, it's my fault, thank you! I know, I already use this skill many times, but use & directly for a template type seems not work, for example: r = pENGINE->RegisterObjectBehaviour("vector<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&, bool&)", asFUNCTION(TmplValidationCB1), asCALL_CDECL); // ^ ^ r = pENGINE->RegisterObjectBehaviour("vector<T>", asBEHAVE_FACTORY, "vector<T>@ f(int&)", asFUNCTION(CStdVector::Create), asCALL_CDECL); // ^ r = pENGINE->RegisterObjectBehaviour("vector<T>", asBEHAVE_FACTORY, "vector<T>@ f(int&in, size_t, const T&)", asFUNCTION(CStdVector::CreateValue), asCALL_CDECL); // ^ r = pENGINE->RegisterObjectMethod("vector<T>", "void resize(const size_t nNewLEN, const T& iVALUE)", asMETHODPR(CStdVector, resize, (const size_t, void* const), void), asCALL_THISCALL); // ^ The above four lines of code will all end up with some error message. As far as I understand, these are caused by the unfinished works of AS engines mentioned above?
  2. I want create something like "vector::iterator<T>", I create it using following codes: r = pENGINE->RegisterObjectType("iterator<T>", sizeof(CStdVecItor<VEC, VALUE>), asOBJ_VALUE|asOBJ_APP_CLASS_CDAK|asOBJ_APP_CLASS_ALLINTS|asOBJ_TEMPLATE); assert(r >= 0); It use a combination of asOBJ_VALUE and asOBJ_TEMPLATE. But the engine cry when I try to define a constructor for it: r = pENGINE->RegisterObjectBehaviour("iterator<T>", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION((CStdVecItor<VEC, VALUE>::Construct)), asCALL_CDECL_OBJLAST); I traced into the as_scriptengine.cpp, and found the problem appeared here: // The templates take a hidden parameter with the object type if( (objectType->flags & asOBJ_TEMPLATE) && (func.parameterTypes.GetLength() == 0 || !func.parameterTypes[0].IsReference()) ) { WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_FIRST_PARAM_MUST_BE_REF_FOR_TEMPLATE_FACTORY); return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); } So I can not define a asOBJ_VALUE type template yet? For something like vector::iterator, it basically only a integer (pointer). Obviously, providing an asOBJ_REF wrapper for such an integer is expensive. So could we add support for "asOBJ_VALUE|asOBJ_TEMPLATE"? PS: We always set asEP_ALLOW_UNSAFE_REFERENCES to true, however, due to the AS engine's template-related code also contains some unfinished work, such as: // TODO: If unsafe references are allowed, then inout references allow value types So that we can't write the reference parameters in the desired way. Hope that these tasks can be completed sooner :-D In my mind, even if you have set asEP_ALLOW_UNSAFE_REFERENCES to true, the &in and &out references still produce extra copies, right? This is not what we expect. Thanks :-)
  3. Add a callback for the GarbageCollect API

    Yes, exactly. :-D Yes, because there may be various interactions between application types and script types. So I think it would be a good idea to return a set of asITypeInfo collections that are circularly referenced to each other in each callback, whether they are application type or script type. For example, in the previous example, class B may be an application type, while A and C are script types.
  4. Can we add a callback for the "asIScriptEngine::GarbageCollect" API. In this way, the application can use this callback function to know which types have circular references to each other: MyGcCallback(const asITypeInfo** ppCircleRef, ...) { while (*ppCircleRef) { cout << "class '" << (*ppCircleRef++)->GetName() << "' "; } cout << "refer to each other and form a circular reference." } // May output: // class 'A' class 'B' class 'C' refer to each other and form a circular reference." With this callback, we can fire a full GC manually, find out if there are circular references in the current code and where it is. This allows us to turn off the automatic GC function and use only the manual GC as an inspector to find the circular references, and fix it in the code.
  5. Ok, then could I define two template with same name and different number of template argument: engine->RegisterObjectType("vector<class VAL>", ...); engine->RegisterObjectType("vector<class VAL, class GC>", ...); Can the AS engine correctly overload them when compiling the script? Thanks :-)
  6. There are actually two questions: 1. Can I specify a primary type as the template argument. 2. Give it a default value. For example: "engine->RegisterObjectType("vector<class VAL, bool bForceNoGC = false>", ...); " just like C++. Or if the first one is not possible, then can I just give the template argument a default value like: // define some dummy types engine->RegisterObjectType("AUTOGC", sizeof(AUTOGC), asOBJ_VALUE|asOBJ_POD|asOBJ_APP_PRIMITIVE); engine->RegisterObjectType("NOGC", sizeof(NOGC), asOBJ_VALUE|asOBJ_POD|asOBJ_APP_PRIMITIVE); engine->RegisterObjectType("vector<class VAL, class GC = AUTOGC>", ...);
  7. Template specializations for value types

    OK, thanks. I think it is useful because strictly speaking, containers in C++ STL (std::vector, std::map and etc.) are all value types: You can definitely instantiation a std::vactor<int> object on the stack. :-)
  8. Template specializations for value types

    BTW: Can I define a template using these flags: asOBJ_VALUE | asOBJ_GC | asOBJ_TEMPLATE ? A VALUE type with GC support?
  9. I am a bit confused, should the new callback function be called in the catch block? if so, you can rethrow it in any C++98 compiler like this: MyExceptionCallback(...) { try { throw; // rethrow current exception } catch (const ExpA& err) { // ... } catch (const ExpB& err) { // ... } catch (const ExpC& err) { // ... } catch (...) { // ... } } So why we need use the C++11 features? :-)
  10. EDIT: By learn the scriptarray.cpp code and reread the document carefully, I found the asBEHAVE_TEMPLATE_CALLBACK callback already can do this optimization, Sorry for my carelessness. :-( Can I define a template partial specialization for all VALUE / PRIMARY types? For example: Can I define a partially specialization for a simple "vector" container template, so we can save some useless operations (i.e., GC, ...) to enhance the performance. Or, can we safely do nothing within the related callbacks if we known we are a "VALUE type" container? Like this: void CStdVector::EnumReferences(asIScriptEngine *engine) { if (!this->m_bIsRefObj) { return; // this is a container of VALUE or PRIMARY type } for (...) { engine->GCEnumCallback(...); } } Thanks :-)
  11. More generally, It would be even better if the AS could support exceptions and interoperate with C++ exception mechanisms. :-D
  12. Ok, thank you. Therefore, the number of memory copies did not increase, it has just transferred from the engine to the user code with many additional improvements. It's great! :-D
  13. @WitchLord For the asIStringFactory::GetStringConstant(const char *data, asUINT length) API: The lifetime of the "data" parameter is longer than the script that will use it, right? So instead of reallocating memory and then copy it again, we can save this pointer directly? (Our string class support bind to the "static" or "external" data). EDIT: I've made a small test of it, and found the content of the data argument will be invalided soon. So, different from the past, we need reallocate a heap buffer, and copy its content to there now. From this respect, I think it is not as efficiency as the old StringFactory callback (at least for a string class that can be bound to "externel" pointer) :-P Or, Another possibility is that the new engine saves a memory copy, so the overall efficiency is actually the same?
  • Advertisement