Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


dkrusu

Member Since 09 Dec 2012
Offline Last Active Apr 13 2015 07:16 PM

Topics I've Started

Namespace Bug?

11 April 2015 - 12:43 PM

I've encountered a bug with namespaces, if you create a object type inside of a namespace besides the global, then create a global property with the same name as the object type but in the global namespace,  the opIndex method fails. The following code should show whats going on more than my explanation

#include "angelscript.h"
#include <stdio.h>

void MessageCallback(const asSMessageInfo *msg, void *param)
{
	const char *type = "ERR ";
	if( msg->type == asMSGTYPE_WARNING ) 
		type = "WARN";
	else if( msg->type == asMSGTYPE_INFORMATION ) 
		type = "INFO";

	printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}

class FooObj
{
    public:
        FooObj() { };

        int operator[](int num)
        {
            return 1;
        }

        void test() { }
};

int main()
{
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);

    engine->SetDefaultNamespace("NSBugTest");
    engine->RegisterObjectType("FooObj", 0, asOBJ_REF | asOBJ_NOCOUNT);
    engine->RegisterObjectMethod("FooObj", "int opIndex(int)", asMETHOD(FooObj, FooObj::operator[]), asCALL_THISCALL);
    engine->RegisterObjectMethod("FooObj", "void test()", asMETHOD(FooObj, FooObj::test), asCALL_THISCALL);
    engine->SetDefaultNamespace("");

    FooObj foo;
    engine->RegisterGlobalProperty("NSBugTest::FooObj FooObj", &foo);

    asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
	mod->AddScriptSection("test",
			"void main() \n"
			"{ \n"
            "   FooObj.test();\n"
            "   int num = FooObj[0];\n"
			"} \n");
	mod->Build();

    return 0;

}

The call to test() will work like it should, however the opIndex call generates the following error:

test (1, 1) : INFO : Compiling void main()
test (4, 21) : ERR  : Expected ']'
test (4, 21) : ERR  : Instead found '<integer constant>'

Thanks


Bug in type-casting

13 December 2014 - 12:03 AM

I've encountered a bug when using implicit ref casting. All of my widget objects inherit from a Base class that then has a implicit cast for each widget type. The findWidget() method returns a reference to a Base object and then is casted to the Label object. If I try to assign the reference to a class property it can't resolve the method call for setText(). Creating a local variable works just fine.

class CobaltTheme
{
    private const Widgets::Label @mClock;

    CobaltTheme()
    {
        @mClock = Window.findWidget("Home.Clock");    

        onTimerCallback @timerCallback = onTimerCallback(this._clockTimer);
        createTimer(1, timerCallback);
    }

    bool _clockTimer()
    {
        //  ERR  : No matching signatures to 'Label::setText(string) const'
        mClock.setText(timeToString("%I:%M%P"));

        // Works fine:
        Widgets::Label @Clock = Window.findWidget("Home.Clock");
        Clock.setText(timeToString("%I:%M%P"));
        return true;
    }
}
// The Base to Label reference cast
r = engine->RegisterObjectBehaviour("Base", asBEHAVE_IMPLICIT_REF_CAST, "Label@ f()", asFUNCTION(Base::castToLabel), asCALL_CDECL_OBJLAST); assert( r >= 0 );
    
r = engine->RegisterObjectMethod("Window", "Widgets::Base@ findWidget(const string &in)", asMETHOD(Window, findWidget), asCALL_THISCALL); assert( r >= 0 );

Thanks


Initializing array in function call

16 January 2014 - 12:01 PM

Any chance of allowing a initialization list to be used in a function call?

void test(array<string> &in); // Function definition

test({"string1", "string2"});

Or something like:

test(array<string>{"string1", "string2"});

- dave


GetDefaultNamespace()

05 January 2013 - 10:50 PM

Could you add a method to get the current default namespace?

 

const char *asCScriptEngine::GetDefaultNamespace() const
{
    return defaultNamespace->name.AddressOf();
}

 

Thanks,

Dave Krusu


Segfault

01 January 2013 - 11:26 PM

I'm getting a segfault when registering a object with a method that returns a handle to it's self. The following code reproduces the crash:

 

#include <angelscript.h>
#include <stdio.h>

class IManaged {
    public:
        virtual void addRef() = 0;
        virtual void Release() = 0;
};

class Test : public IManaged {
    public:
        void addRef() {

        }

        void Release() {

        }

        Test &Foo() {
            return *this;
        }
};

Test *pTest;

int main() {
    asIScriptEngine *pEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
    asIScriptModule *Mod     = pEngine->GetModule(0, asGM_ALWAYS_CREATE);

    pTest = new Test();

    pEngine->RegisterObjectType("Test", 0, asOBJ_REF);
    pEngine->RegisterObjectBehaviour("Test", asBEHAVE_ADDREF, "void f()", asMETHOD(Test, addRef), asCALL_THISCALL);
    pEngine->RegisterObjectBehaviour("Test", asBEHAVE_RELEASE, "void f()", asMETHOD(Test, Release), asCALL_THISCALL);
    pEngine->RegisterObjectMethod("Test", "Test &Foo()", asMETHOD(Test, Foo), asCALL_THISCALL);
    pEngine->RegisterGlobalProperty("Test @pTest", pTest);

    const char *Script = "void main() { pTest.Foo(); }";

    Mod->AddScriptSection("script", Script);
    Mod->Build();

    asIScriptContext *Ctx = pEngine->CreateContext();
    asIScriptFunction *Func = Mod->GetFunctionByDecl("void main()");

    Ctx->Prepare(Func);
    Ctx->Execute();

    return 0;
}

 

here is the backtrace:

 

#0  0x0000000000412682 in asCScriptEngine::CallObjectMethod (this=0x737010,
    obj=0x4c5e30 <vtable for Test+16>, i=0x7400f0, s=0x740150)
    at ../../source/as_scriptengine.cpp:3382
#1  0x0000000000412574 in asCScriptEngine::CallObjectMethod (this=0x737010,
    obj=0x4c5e30 <vtable for Test+16>, func=31)
    at ../../source/as_scriptengine.cpp:3354
#2  0x0000000000490b73 in asCContext::ExecuteNext (this=0x740ae0)
    at ../../source/as_context.cpp:3739
#3  0x00000000004896af in asCContext::Execute (this=0x740ae0)
    at ../../source/as_context.cpp:1155
#4  0x00000000004026c7 in main () at test.cpp:48

 

 

This happends on both 32 and 64-bit builds with GCC 4.7.2 (Linux)

 

Thanks,

Dave

 


PARTNERS