FOnline Development > Share Your Work

Get useful Infos using AngelScript and C++

(1/1)

adumbperson:
3 functions exploiting AngelScript's API to reflect global vars/funcs also classes, their properties and member functions.
To use the functions you have to bind their calls using _defines.fos (look at end) and add it:

--- Code: ---// Test function
# ifdef __SERVER
#  pragma bindfunc "void GetObjectType()      -> fonline_test.dll GetObjectType"
#  pragma bindfunc "void GetGlobalFunc()      -> fonline_test.dll GetGlobalFunc"
#  pragma bindfunc "void GetGlobalProperty()  -> fonline_test.dll GetGlobalProperty"
# endif
# ifdef __CLIENT
#  pragma bindfunc "void GetObjectType()      -> fonline_test_client.dll GetObjectType"
#  pragma bindfunc "void GetGlobalFunc()      -> fonline_test_client.dll GetGlobalFunc"
#  pragma bindfunc "void GetGlobalProperty()  -> fonline_test_client.dll GetGlobalProperty"
--- End code ---
also you shud add it to fonline_test.cpp

--- Code: ---EXPORT void GetGlobalProperty()
{
    // global properties
    Log("##################### global properties #####################\n");
    for( asUINT i = 0; i < ASEngine->GetGlobalPropertyCount(); i++ )
    {
        const char *name;
        const char *pnamespace;
        int typeId;
        bool isConst;
        const char *configGroup;
        void *pointer;
        asDWORD accessMask;
        ASEngine->GetGlobalPropertyByIndex( i, &name, &pnamespace, &typeId, &isConst, &configGroup, &pointer, &accessMask);
        if (name) {
            Log("%s %s\n", ASEngine->GetTypeDeclaration(typeId, true), name);
        }
    }
}

EXPORT void GetGlobalFunc()
{
    // global functions
    Log("##################### global functions #####################\n");
    for( asUINT i = 0; i < ASEngine->GetGlobalFunctionCount(); i++ )
    {
        asIScriptFunction * ptr;
        ptr = ASEngine->GetGlobalFunctionByIndex( i );
        if (ptr) {
            Log("%s\n", ptr->GetDeclaration(true,true));
        }
    }
}

EXPORT void GetObjectType()
{
    // objects
    Log("##################### objects #####################\n");
    for( asUINT i = 0; i < ASEngine->GetObjectTypeCount(); i++ )
    {
        asIObjectType * ptr;
        ptr = ASEngine->GetObjectTypeByIndex( i );
        Log("##################### %s #####################\n", ptr->GetName());
        // through member properties
        for(asUINT p = 0; p < ptr->GetPropertyCount(); ++p)
            Log("%s\n", ptr->GetPropertyDeclaration(p) );

        // through member functions
        for (asUINT x = 0; x < ptr->GetMethodCount(); ++x)
        {
            asIScriptFunction * assf;
            assf = ptr->GetMethodByIndex(x, false);
            Log("%s\n", assf->GetDeclaration(true,false) );
        }
    }
}

--- End code ---

Then after that you should compile the dlls... and you can start using it directly with AScompiler.exe:

--- Code: ---ASCompiler.exe runme.fos -run main  > smartsense.h
ASCompiler.exe runme.fos -client -run main  > smartsense.h
--- End code ---
something alike depending your environment...

runme.fos:

--- Code: ---#include "_defines.fos"

void main()
{
    GetGlobalProperty();
    GetGlobalFunc();
    GetObjectType();
}

--- End code ---

Thank to wipe.

Navigation

[0] Message Index

Go to full version