SonyWWS / LevelEditor

The ATF LevelEditor is a powerful tool for constructing and assembling game levels. It provides a WYSIWYG interface and allows you to place objects, edit properties, edit terrain, and build game levels.
Apache License 2.0
1.32k stars 230 forks source link

autogenerate different getter code for strings and wide strings #36

Open jethac opened 8 years ago

jethac commented 8 years ago

I was having some difficulty marshalling a native wide string property into a managed string when I realised the code CodeGenDom was giving me was wrong.

The patch is somewhat self-explanatory - when it's a string, we want to:

  1. C-style cast the char* or wchar_t* string pointer (not the address of the pointer), to a void pointer, and
  2. Use the appropriate string-length function (strlen / wcslen) instead of sizeof

Seeing as the repository includes the binaries, I thought about providing rebuilt binaries, but it might be easier to merge without them.

abeckus commented 8 years ago

Your changes will break the interface for getting object property. The size must always be in bytes and data is always is void. In C# side you should convert void data to string using property encoder.

<code langu /*

jethac commented 8 years ago

Ahh, breaking the interface would be bad. I'm a little concerned that we're talking past each other at the moment though; with the current pre-patch code, when you have an element in your XSD containing:

<LeGe.NativeProperty name="mystring" nativeName="MyString" nativeType="wchar_t*" access="get">

The auto-generated code will be:

void MyClass_MyString_Get(ObjectGUID instanceId, void** data, int* size)
{
    MyClass* instance = reinterpret_cast<MyClass*>(instanceId);
    static wchar_t* localData;
    localData = instance->GetMyString();
    *data = (void*)&localData;
    *size = sizeof(localData);
}

Which doesn't seem right, seeing as:

Is that what was intended?

abeckus commented 8 years ago

Thanks for clarifying it, I will test the CodeGen with getter of type wchar_t* and fix the issue in the next update. please make a local fix, until I update master branch.

Alan

jethac commented 8 years ago

Thanks Alan! :smile: