Sfoglia il codice sorgente

Allow CFunctions to be pushed

Ole Krüger 10 anni fa
parent
commit
23c98278c0
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  1. 17 0
      lib/luwra/types.hpp

+ 17 - 0
lib/luwra/types.hpp

@@ -79,6 +79,14 @@ int Push(State* state, T value) {
 		(luaL_checktype(state, n, LUA_TBOOLEAN), lua_toboolean(state, n))
 #endif
 
+#ifndef luaL_checkcfunction
+	/**
+	 * Check if the value at index `n` is a C function and retrieve it.
+	 */
+	#define luaL_checkcfunction(state, n) \
+		(luaL_checktype(state, n, LUA_TCFUNCTION), lua_toboolean(state, n))
+#endif
+
 #ifndef luaL_pushstdstring
 	/**
 	 * Push a `std::string` as string onto the stack.
@@ -212,6 +220,15 @@ LUWRA_DEF_VALUE(std::string, luaL_checkstring,  luaL_pushstdstring);
 #undef LUWRA_DEF_VALUE
 #undef LUWRA_DEF_NUMERIC
 
+template <>
+struct Value<CFunction> {
+	static inline
+	int Push(State* state, CFunction fun) {
+		lua_pushcfunction(state, fun);
+		return 1;
+	}
+};
+
 /**
  * An arbitrary value on an execution stack.
  * Note: this value is only available as long as it exists on its originating stack.