🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Angel Script BNF grammar

Started by
11 comments, last by AlphaDog 19 years ago
Quote: Original post by AlphaDog
If you need to pass pointers around between your script objects. I found that wrapping boost::any in a simple object with a templated get member function seems to work well and keep things relatively type-safe. Let me know if you are interested and I'll post the code here...

~Scott



Yes, I'd like to see it.

What my problem is that I have to use simple c arrays not std::vectors in my application.
Advertisement
Quote: Original post by WitchLord
AngelScript arrays are not compatible with C++ arrays, since AngelScript needs to do bounds-checking, etc.

If you want to be able to pass arrays between C++ and AngelScript, you'll have to override AngelScripts built-in array type with a type that both AngelScript and C++ can understand.

As Rain Dog said, you can do this by registering the std::vector implementation, using Deyja's code. That code is available in the AngelScript zip file, under /tests/test_feature/source/stdvector.h.

Regards,
Andreas

PS. I'm not sure if I'd like to let a computer program do my stock exchange business' for me [wink], but even so it is an interesting project you have going there.



The aim of my application is not to substitude human but to assist people in stock trading. The trading rules are generated by an A.I. algorithm and then put into a simulation system to test them. The rules with good performance are selected.

ps: My English is not good,please dont laugh at me. :)

[Edited by - winplusx on June 20, 2005 10:58:58 PM]
Here is the code, and a really scaled down example so there is very little error checking. enjoy...

class CPtr{public:    CPtr()    {    }    CPtr(boost::any &myany): m_ptr(myany)    {    }    CPtr &operator=( const CPtr &rhs )    {        this->m_ptr = rhs.m_ptr;        return *this;    }    template<typename T>    T get( void )    {        T pRet = NULL;        try        {            pRet = boost::any_cast < T > ( m_ptr );        }        catch (const boost::bad_any_cast &)        {                pRet = NULL;        }        return pRet;    }    static void RegisterPtr( asIScriptEngine *as )    {        int err = as->RegisterObjectType("Ptr",sizeof(CPtr),asOBJ_CLASS | asOBJ_CLASS_CONSTRUCTOR ); assert( r >= 0 );        err = as->RegisterObjectBehaviour("Ptr", asBEHAVE_CONSTRUCT, "void CTor()", asFUNCTIONPR(Constructor, (CPtr*), void), asCALL_CDECL_OBJLAST);assert( r >= 0 );        err = as->RegisterObjectBehaviour("Ptr", asBEHAVE_ASSIGNMENT, "Ptr &f(const Ptr &in)",asMETHODPR(CPtr, operator =, (const CPtr&), CPtr&), asCALL_THISCALL);assert( r >= 0 );    }private:    boost::any m_ptr;};// If you passing this back and forth to an object // you might have a script object like thisclass CMyScriptObj{    public:        static void RegisterMyObj( asIScriptEngine *as )        {                int r = engine->RegisterObjectMethod("MyScriptObject", "int setPtr(Ptr &in)", asMETHOD(CMyScriptObj,setPtr), asCALL_THISCALL); assert(r >= 0);                r = engine->RegisterObjectMethod("MyScriptObject", "Ptr getPtr()", asMETHOD(CMyScriptObj,getPtr), asCALL_THISCALL); assert(r >= 0);        }        CPtr gePtr( void )        {           return CPtr(boost::any(m_pObj));        }        void setPtr( CPtr &ptrObj )        {           CMyScriptObj* pMyObj = ptrObj.get<CMyScriptObj*>();            if(pMyObj)                m_pObj = pMyObj;        }    private:        CMyScriptObj* m_pObj;}// To use this in ASMyScriptObject object();Ptr ptr = object.getPtr();object.setPtr( ptr );
[size=1]'Behold! It is not over unknown seas but back over well-known years that your quest must go; back to the bright strange things of infancy and the quick sun-drenched glimpses of magic that old scenes brought to wide young eyes.'

This topic is closed to new replies.

Advertisement