Page 3 of 3 FirstFirst 123
Results 51 to 55 of 55

Thread: Export strings to pascal

  1. #51
    Join Date
    Jul 2009
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    66 Post(s)

    Default

    Hah you are too smart. I could have never figured this stuff out.

  2. #52
    Join Date
    Jul 2009
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    66 Post(s)

    Default

    Hey Brandon, today I tried your code out. It keeps complaining that "SomeRecord" is unknown declaration. Then I decided to do some analysis of Simbas calls.
    Setup.
    Code:
    ////////////////////////plugincalls////////////////////////////////////
    extern "C" int __declspec(dllexport) GetPluginABIVersion()
    {
    	cout << "1" << endl;
    	return 2;
    }
    
    extern "C" int __declspec(dllexport) GetTypeInfo(int Index, char** Type, char** Definition)
    {
    	cout << "2" << endl;
    	if (Index < PascalTypeCount)
    	{
    		strcpy(*Type, PascalTypes[Index * 2 + 0]);
    		strcpy(*Definition, PascalTypes[Index * 2 + 1]);
    		return Index;
    	}
    	return 0;
    }
    
    extern "C" int __declspec(dllexport) GetTypeCount()
    {
    	cout << "3" << endl;
    	return PascalTypeCount;
    }
    
    extern "C" int __declspec(dllexport) GetFunctionInfo(int Index, VOID** Address, CHAR** Definition)
    {
    	cout << "4" << endl;
    	if (Index < PascalExportCount)
    	{
    		*Address = (void*)GetProcAddress(module, PascalExports[Index * 2]);
    		strcpy(*Definition, PascalExports[Index * 2 + 1]);
    		return Index;
    	}
    	return -1;
    }
    
    extern "C" int __declspec(dllexport) GetFunctionCount()
    {
    	cout << "5" << endl;
    	return PascalExportCount;
    }
    
    extern "C"  __declspec(dllexport) void SetPluginSimbaMethods(TSimbaMethods Methods)
    {
    	PLUGIN_SYNC_METHODS = Methods;
    }
    
    extern "C"  __declspec(dllexport) void SetPluginSimbaMemoryAllocators(TSimbaMemoryAllocators Allocators)
    {
    	cout << "SetPluginSimbaMemoryAllocators called" << endl;
    	PLUGIN_MEMORY_ALLOCATORS = Allocators;
    }
    ///////////////////////////////////////////////////////////////////////
    I have added couts to get order, output:
    Code:
    STARTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
    5
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    4
    3
    2
    SetPluginSimbaMemoryAllocators called
    Unknown declaration "SomeRecord" at line 1, column 14 in file "!addGlobalType::SomeRecord" at line 3, column 11 in file "C:\Users\Al\Documents\Simba64\Scripts\serenspiritwatch.simba"
    I don't know, shouldn't variables to be called before functions trying to use them :P
    Edit:Removed function that uses "SomeRecord". Still gives that same error.
    It is all copy paste, how it could not work.
    Code:
    static const char* PascalTypes[] =
    {
    	 "SomeRecord", "SomeRecord", R"(
                           packed record
                              x, y: Int32;
                              txt: String;
                           end;
        )"
    };
    Edit:
    Changed code into:
    Code:
    static const char* PascalTypes[] =
    {
    	 "SomeRecord", "record x, y: Int32; txt: String; end;"
    
    };
    Now it works. When clicking in Simbas plugin record thing it shows:
    Code:
    Declaration:
    SomeRecord = record x, y: Int32; txt: String; end
    But thanks. What is difference between packed record and just record? Btw GetPluginABIVersion is never called/used.

  3. #53
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by alar82 View Post
    Now it works. When clicking in Simbas plugin record thing it shows:
    Code:
    Declaration:
    SomeRecord = record x, y: Int32; txt: String; end
    But thanks. What is difference between packed record and just record? Btw GetPluginABIVersion is never called/used.
    yeah what you have is correct.
    The function should be called. It gets called for me

    The difference between a packed record and regular record is the alignment.

    For example:

    c++ Code:
    struct Foo
    {
        int a;
        int b;
        char c;
        int d;
    };

    The size of this structure in my compiler is `sizeof(int) * 4 => 16`. WHY though? There are only 3 integers and a single char! Well.. turns out for various reasons, the compiler will `PAD` the structure to align on the nearest DWORD boundary.. IE: That char will be padded to an int..

    IF you pack the structure or specify that it should be packed or aligned on a boundary of your choice (IE: 1).. then the compiler will NOT do this padding..

    So in order to guarantee that Simba has the same padding as your plugin, we ask Simba to pack the record/struct tightly AND we ask our compiler to do the same for our struct.. Therefore they both have the same alignment and same size and we access the fields at the same offset


    See: https://stackoverflow.com/questions/...ng-and-packing
    I am Ggzz..

  4. #54
    Join Date
    Jul 2009
    Posts
    154
    Mentioned
    5 Post(s)
    Quoted
    66 Post(s)

    Default

    Hey Brandon I noticed that strcpy wants char* type to copy but in my structs there are strings not chars.
    Edit: Made struct specially for exporting out. Now i can:
    Code:
    	 arr[i].Action = AllocateString<char>(AllNPC[i].Name.length());
             strcpy(arr[i].Action, AllNPC[i].Name.c_str());
    Edit:Nvm.

  5. #55
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    @alar82 and @here, change the `refCount` to 0 by default (as shown below):

    C++ Code:
    template<typename T>
    T* AllocateArray(std::size_t size, std::size_t element_size) noexcept
    {
        //other code here..
        ptr->refCount = 0;  //CHANGE THIS LINE TO 0 IN YOUR CODE
        //other code here..
    }

    template<typename T>
    T* AllocateString(std::size_t size, std::size_t element_size) noexcept
    {
        //other code here..
        ptr->refCount = 0;  //CHANGE THIS LINE TO 0 IN YOUR CODE
        //other code here..
    }
    I am Ggzz..

Page 3 of 3 FirstFirst 123

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •