[font="arial, verdana, tahoma, sans-serif"]
You could create a batch exporter that takes class information and functions and exposes a "Process" function that automatically registers the class methods. But in the end, it really is no different than calling the engine functions themselves.
[/font]What I'm trying to make is something like ChaiScript's bind system. For normal functions, it works fine... it detects calling conventions, parameter types and return types. I can change exported function prototypes without touching the export function. The problem is not exporting class functions at all, it's exporting all types of new objects. Since I need to manually put all the function prototypes by hand as string, that can be a real pain if prototype changes during the development.
[font="arial, verdana, tahoma, sans-serif"]
This looks neat. But I have a question for you. How do you decide how a reference parameter or pointer in a C++ function should be registered in AngelScript? This cannot be done automatically in all scenarios. I mean a reference parameter may be registered as &in, &out, or &inout depending on what the function is supposed to do. Likewise a pointer parameter may also have multiple translations, &out, @, etc.
As for classes. Unfortunately I do not believe there is any way of automatically detecting available methods and properties through meta-programming, so I think what you'll need to do is to expose methods to register the type, functions, and properties one by one.
[/font][font="arial, verdana, tahoma, sans-serif"]The current algorithm parses the function generating it's associated string prototype. Examples: [/font][font="arial, verdana, tahoma, sans-serif"]I'll be using "test" as the name of the function I'd like to export, and if I pass it to the parser function like:[/font]
[font="arial, verdana, tahoma, sans-serif"]
std::string GenPrototype<F>(F f)
int test()
GenPrototype(&test);
returns "int test()"
void test()
returns "void test()"
unsigned int test()
returns "uint test()"
long long test()
returns "int64 test()"
std::string test()
returns "string test()"
std::string* test()
returns "string@ test()"
MyType test()
returns "MyType test()"
MyType* test()
returns "MyType@ test()"
and so on... it works the same way for parameters:
void test(int, std::string, unsigned int)
returns "void test(int, string, uint)"
void test(MyType, MyType*)
returns "void test(MyType, MyType@)"
[/font]
If I understood you right, this can be done by using a helper struct template by making a template like:
void test(Param::In<int>, Param::Out<int>);
But I haven't tought about this yet, since I don't know all the string prototype scenarios... I'm working only on basic types for now.
I have other question:
When exporting object types that is managed by the application (cannot be instantied, instances will be set by the application into the global variable scope), what's the best way to do that?
Just skipping bind the constructor/destructor? Or there's a more reliable way to do that?