Sign in to follow this  

Problem binding two similarly-named objects in different namespaces

This topic is 1966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

[code]
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("");
}
[/code]

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[code]
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 *'
[/code]

Share this post


Link to post
Share on other sites
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:

[code]
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("");
}
[/code]

Share this post


Link to post
Share on other sites
Looks like you've found another bug with the namespace feature. I'll look into it tomorrow.

In the meantime try this:

[code]
Engine->RegisterObjectProperty("event", "keyboard::event_type type", asOFFSET(event, type));
[/code]

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

Regards,
Andreas

Share this post


Link to post
Share on other sites

This topic is 1966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this