Explorar el Código

Allow NativeFunctions to be callable without parameters

Ole hace 9 años
padre
commit
144b7bc53d
Se han modificado 1 ficheros con 17 adiciones y 0 borrados
  1. 17 0
      lib/luwra/functions.hpp

+ 17 - 0
lib/luwra/functions.hpp

@@ -47,6 +47,17 @@ struct NativeFunction: Reference {
 		Reference(state, index)
 	{}
 
+	inline
+	R operator ()() {
+		impl->push();
+
+		lua_call(impl->state, 0, 1);
+		R returnValue = Value<R>::read(impl->state, -1);
+
+		lua_pop(impl->state, 1);
+		return returnValue;
+	}
+
 	template <typename... A> inline
 	R operator ()(A&&... args) {
 		impl->push();
@@ -70,6 +81,12 @@ struct NativeFunction<void>: Reference {
 		Reference(state, index)
 	{}
 
+	inline
+	void operator ()() {
+		impl->push();
+		lua_call(impl->state, 0, 0);
+	}
+
 	template <typename... A> inline
 	void operator ()(A&&... args) {
 		impl->push();