Problem binding two similarly-named objects in different namespaces

Started by
9 comments, last by WitchLord 11 years, 8 months ago
I'm trying to add keyboard support to a codebase that has so far only supported PS3 controllers - there are two structs that I'd like to expose to AS: ps3_controller::event and keyboard::event. Here's how I'm binding both:


void bind_ps3_controller(asIScriptEngine* Engine)
{
using namespace ps3_controller;
int Result = 0;
Result = Engine->SetDefaultNamespace("ps3_controller");
Result = Engine->RegisterGlobalProperty("const int down", const_cast<int*>(&ps3_controller::down));
assert(Result >= 0);
Result = Engine->SetDefaultNamespace("ps3_controller::button");
Result = Engine->RegisterGlobalProperty("const int cross", const_cast<int*>(&ps3_controller::button::cross));
assert(Result >= 0);
Result = Engine->SetDefaultNamespace("ps3_controller::analog");
Result = Engine->RegisterGlobalProperty("const int LStickX", const_cast<int*>(&ps3_controller::analog::LStickX));
Result = Engine->RegisterGlobalProperty("const int LStickY", const_cast<int*>(&ps3_controller::analog::LStickY));
Result = Engine->RegisterGlobalProperty("const int RStickX", const_cast<int*>(&ps3_controller::analog::RStickX));
Result = Engine->RegisterGlobalProperty("const int RStickY", const_cast<int*>(&ps3_controller::analog::RStickY));
//
Result = Engine->SetDefaultNamespace("ps3_controller");
Engine->RegisterObjectType("event", sizeof(ps3_controller::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "int source", asOFFSET(event, source));
Engine->RegisterObjectProperty("event", "int state", asOFFSET(event, state));
Engine->RegisterObjectProperty("event", "float value", asOFFSET(event, value));
//
Result = Engine->SetDefaultNamespace("");
}

void bind_keyboard(asIScriptEngine* Engine)
{
using namespace keyboard;
int Result = 0;
Result = Engine->SetDefaultNamespace("keyboard");
Engine->RegisterEnum("event_type");
Engine->RegisterEnumValue("event_type", "key_down", keyboard::key_down);
Engine->RegisterEnumValue("event_type", "key_up", keyboard::key_up);
Engine->RegisterEnumValue("event_type", "key_repeat", keyboard::key_repeat);
Engine->RegisterObjectType("event", sizeof(keyboard::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "event_type type", asOFFSET(event, type));
Engine->RegisterObjectProperty("event", "int code", asOFFSET(event, code));
//
Result = Engine->SetDefaultNamespace("");
}


However I seem to get the following output when I try to register keyboard event's time member:

"Property (1, 8) : ERR : Name conflict. 'time' is an object property.
(0, 0) : ERR : Failed in call to function 'RegisterObjectProperty' with 'event' and 'uint64 time'"

What am I missing here? As far as I understand, the keyboard bindings should be in a keyboard namespace and the object's shouldn't alias. What am I doing wrong?
Holy crap I started a blog - http://unobvious.typepad.com/
Advertisement
I'll look into this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm sorry for taking so long to look into this problem.

I believe you're facing a bug that has already been fixed in the latest release, more specifically in revision 1315 checked in on May 24th.

Which version of AngelScript are you using? If you're on a version 2.23.1 or earlier, I suggest you upgrade AngelScript to the latest release.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I was using 2.23.1. I'm trying to transition to the latest release but the script array addon seems to have build errors with that one - am I doing something wrong or hasn't the addon been updated to match newer API?
Holy crap I started a blog - http://unobvious.typepad.com/
I'm not aware of any problems with the add-ons.

What is the error you're seeing?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


scriptarray.cpp:80:9: Cannot initialize a variable of type 'int' with an rvalue of type 'asIScriptFunction *'
scriptarray.cpp:99:27: No member named 'GetFactoryIdByIndex' in 'asIObjectType'; did you mean 'GetFactoryByIndex'?
scriptarray.cpp:99:9: Cannot initialize a variable of type 'int' with an rvalue of type 'asIScriptFunction *'
scriptarray.cpp:301:25: No member named 'CopyScriptObject' in 'asIScriptEngine'; did you mean 'CreateScriptObject'?
scriptarray.cpp:301:47: Too many arguments to function call, expected 1, have 3
scriptarray.cpp:697:20: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'int'
scriptarray.cpp:794:21: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'const int'
scriptarray.cpp:809:21: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'const int'
scriptarray.cpp:1061:14: No member named 'CopyScriptObject' in 'asIScriptEngine'; did you mean 'CreateScriptObject'?
scriptarray.cpp:1061:35: Too many arguments to function call, expected 1, have 3
scriptarray.cpp:1112:29: No member named 'GetMethodIdByIndex' in 'asIObjectType'; did you mean 'GetMethodByIndex'?
scriptarray.cpp:1112:18: Assigning to 'int' from incompatible type 'asIScriptFunction *'
scriptarray.cpp:1117:28: No member named 'GetMethodIdByIndex' in 'asIObjectType'; did you mean 'GetMethodByIndex'?
scriptarray.cpp:1117:17: Assigning to 'int' from incompatible type 'asIScriptFunction *'
Holy crap I started a blog - http://unobvious.typepad.com/
It appears you don't have the latest version of the scriptarray.cpp add-on. Double check that you got the latest version from the SDK.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks, I updated the add-on code and now it builds. I'm getting a different error from the same keyboard binding code now:

Property (1, 1) : ERR : Identifier 'event_type' is not a data type
(0, 0) : ERR : Failed in call to function 'RegisterObjectProperty' with 'event' and 'event_type type'

The code is:


void bind_keyboard(asIScriptEngine* Engine)
{
using namespace keyboard;
int Result = 0;
Result = Engine->SetDefaultNamespace("keyboard");
Engine->RegisterEnum("event_type");
Engine->RegisterEnumValue("event_type", "key_down", keyboard::key_down);
Engine->RegisterEnumValue("event_type", "key_up", keyboard::key_up);
Engine->RegisterEnumValue("event_type", "key_repeat", keyboard::key_repeat);
Engine->RegisterObjectType("event", sizeof(keyboard::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "event_type type", asOFFSET(event, type));
Engine->RegisterObjectProperty("event", "int code", asOFFSET(event, code));
//
Result = Engine->SetDefaultNamespace("");
}
Holy crap I started a blog - http://unobvious.typepad.com/
Looks like you've found another bug with the namespace feature. I'll look into it tomorrow.

In the meantime try this:


Engine->RegisterObjectProperty("event", "keyboard::event_type type", asOFFSET(event, type));


I believe explicitly specifying the namespace may allow you to work around the bug until I provide a fix.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Awesome, that seemed to work. Thanks for all the help (and the great work on AngelScript)!
Holy crap I started a blog - http://unobvious.typepad.com/

This topic is closed to new replies.

Advertisement