Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add returning reference support #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions include/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,25 @@ class Class : private ClassBase
* @param method The actual method
* @param flags Optional flags
* @param args Argument descriptions
* @param return_ref Return reference or not
* @return Class Same object to allow chaining
*/
Class<T> &method(const char *name, void (T::*method)(), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_0>(method), flags, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_1>(method), flags, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_2>(method), flags, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_3>(method), flags, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_0>(method), Public, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_1>(method), Public, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_2>(method), Public, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_3>(method), Public, args); return *this; }
Class<T> &method(const char *name, void (T::*method)() const, int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_4>(method), flags, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params) const, int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_5>(method), flags, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)() const, int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_6>(method), flags, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params) const, int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_7>(method), flags, args); return *this; }
Class<T> &method(const char *name, void (T::*method)() const, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_4>(method), Public, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params) const, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_5>(method), Public, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)() const, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_6>(method), Public, args); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params) const, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_7>(method), Public, args); return *this; }
Class<T> &method(const char *name, void (T::*method)(), int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_0>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params), int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_1>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(), int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_2>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params), int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_3>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)(), const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_0>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params), const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_1>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(), const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_2>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params), const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_3>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)() const, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_4>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params) const, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_5>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)() const, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_6>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params) const, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_7>(method), flags, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)() const, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_4>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, void (T::*method)(Parameters &params) const, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_5>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)() const, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_6>(method), Public, args, return_ref); return *this; }
Class<T> &method(const char *name, Value (T::*method)(Parameters &params) const, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, static_cast<method_callback_7>(method), Public, args, return_ref); return *this; }

/**
* Add a static method to a class
Expand All @@ -102,16 +103,17 @@ class Class : private ClassBase
* @param method The actual method
* @param flags Optional flags
* @param args Argument descriptions
* @param return_ref Return reference or not
* @return Class Same object to allow chaining
*/
Class<T> &method(const char *name, const native_callback_0 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); return *this; }
Class<T> &method(const char *name, const native_callback_1 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); return *this; }
Class<T> &method(const char *name, const native_callback_2 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); return *this; }
Class<T> &method(const char *name, const native_callback_3 &function, int flags, const Arguments &args = {}) { ClassBase::method(name, function, flags, args); return *this; }
Class<T> &method(const char *name, const native_callback_0 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); return *this; }
Class<T> &method(const char *name, const native_callback_1 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); return *this; }
Class<T> &method(const char *name, const native_callback_2 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); return *this; }
Class<T> &method(const char *name, const native_callback_3 &function, const Arguments &args = {}) { ClassBase::method(name, function, Public, args); return *this; }
Class<T> &method(const char *name, const native_callback_0 &function, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, flags, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_1 &function, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, flags, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_2 &function, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, flags, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_3 &function, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, flags, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_0 &function, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, Public, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_1 &function, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, Public, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_2 &function, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, Public, args, return_ref); return *this; }
Class<T> &method(const char *name, const native_callback_3 &function, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, function, Public, args, return_ref); return *this; }

/**
* Add an abstract method to the class
Expand All @@ -123,10 +125,11 @@ class Class : private ClassBase
* @param name Name of the method
* @param flags Optional flags
* @param args Argument descriptions
* @param return_ref Return reference or not
* @return Class Same object to allow chaining
*/
Class<T> &method(const char *name, int flags, const Arguments &args = {}) { ClassBase::method(name, flags | Abstract, args); return *this; }
Class<T> &method(const char *name, const Arguments &args = {}) { ClassBase::method(name, Public | Abstract, args); return *this; }
Class<T> &method(const char *name, int flags, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, flags | Abstract, args, return_ref); return *this; }
Class<T> &method(const char *name, const Arguments &args = {}, bool return_ref = false) { ClassBase::method(name, Public | Abstract, args, return_ref); return *this; }

/**
* Add a property to the class
Expand Down
29 changes: 16 additions & 13 deletions include/classbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,16 @@ class ClassBase
* @param method The actual method
* @param flags Optional flags
* @param args Description of the supported arguments
* @param return_ref Return reference or not
*/
void method(const char *name, const method_callback_0 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_1 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_2 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_3 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_4 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_5 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_6 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_7 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const method_callback_0 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_1 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_2 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_3 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_4 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_5 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_6 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const method_callback_7 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);

/**
* Add a static method to the class
Expand All @@ -204,20 +205,22 @@ class ClassBase
* @param method The actual method
* @param flags Optional flags
* @param args Description of the supported arguments
* @param return_ref Return reference or not
*/
void method(const char *name, const native_callback_0 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const native_callback_1 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const native_callback_2 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const native_callback_3 &method, int flags=0, const Arguments &args = {});
void method(const char *name, const native_callback_0 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const native_callback_1 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const native_callback_2 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);
void method(const char *name, const native_callback_3 &method, int flags=0, const Arguments &args = {}, bool return_ref = false);

/**
* Add an abstract method to the class
*
* @param name Name of the method
* @param flags Optional flags (like public or protected)
* @param args Description of the supported arguments
* @param return_ref Return reference or not
*/
void method(const char *name, int flags=0, const Arguments &args = {});
void method(const char *name, int flags=0, const Arguments &args = {}, bool return_ref = false);

/**
* Add a property to the class
Expand Down
9 changes: 5 additions & 4 deletions include/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ class Namespace
* @param name Name of the function
* @param function The function to add
* @param arguments Optional argument specification
* @param return_ref Return reference or not
* @return Namespace Same object to allow chaining
*/
Namespace &add(const char *name, const native_callback_0 &function, const Arguments &arguments = {});
Namespace &add(const char *name, const native_callback_1 &function, const Arguments &arguments = {});
Namespace &add(const char *name, const native_callback_2 &function, const Arguments &arguments = {});
Namespace &add(const char *name, const native_callback_3 &function, const Arguments &arguments = {});
Namespace &add(const char *name, const native_callback_0 &function, const Arguments &arguments = {}, bool return_ref = false);
Namespace &add(const char *name, const native_callback_1 &function, const Arguments &arguments = {}, bool return_ref = false);
Namespace &add(const char *name, const native_callback_2 &function, const Arguments &arguments = {}, bool return_ref = false);
Namespace &add(const char *name, const native_callback_3 &function, const Arguments &arguments = {}, bool return_ref = false);

/**
* Add a native class to the namespace by moving it
Expand Down
Loading