I need to create a SimpleDataType, whose instances may refer to a particular node in the tree, which isdoes not have SDT data. So, there is a non-default constructor in the derived class, and I'd like FlexSim bindings to able to use it to create instances.
What I tried:
1. I found a public but undocumented bindConstructor method in the FlexSim Module SDK API. After some experimenting I found that the first parameter should be a static method to be able to compile it. The code below compiles but doesn't work. On start I get a error message "FlexSim encountered an unrecoverable error and must close. Please visit answers.flexsim.com for more help with this issue." Could you please provide an example how to use this bindConstructor?
2. Use bindMethod to bind the static "constructor" method which returns a new instance of the derived type. Version 2 compiles, but there is the same error on start. I suppose that FlexSim signature parser can't recognize the derived class name as the return value.
3. Bind an instance method. Same error. And it's very strange because it uses only built-in Flexscript types, and similar bindings do work in other classes I've written.
// Flexscript wrapper for InterfaceProxy class IProxy : public SimpleDataType { InterfaceProxy iface; public: // default constructor only for createsdtderivative() IProxy() {} IProxy(treenode current, char *ifacename) : iface(current, ifacename) {} virtual const char* getClassFactory() override { return "mymodule::IProxy"; } virtual void bindInterface() override { // 1. compiles, but error on start //bindConstructor(ctor, "IProxy ctor(treenode current, char *ifacename)"); // 2. compiles, but error on start //bindMethod(ctor, IProxy, "IProxy ctor(treenode current, char *ifacename)", BIND_METHOD_STATIC); // 3. compiles, but error on start bindMethod(init, IProxy, "int init(treenode current, char *ifacename)", 0); } int init(treenode current, char *ifacename) { iface.init(current, ifacename); return 0; } static IProxy ctor(treenode current, char* ifacename) { IProxy iproxy(current, ifacename); return iproxy; } };
The error message is not really helpful to localize the problem. Could you please provide an idiomatic example how SDTs with custom constructors are supposed to be initialized?