Pārlūkot izejas kodu

Let NativeFunction check if the parameter is a table, userdata or function

Ole 9 gadi atpakaļ
vecāks
revīzija
72055a0af6
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5 1
      lib/luwra/functions.hpp

+ 5 - 1
lib/luwra/functions.hpp

@@ -77,7 +77,11 @@ struct NativeFunction<void> {
 	inline
 	NativeFunction(State* state, int index):
 		ref(state, index)
-	{}
+	{
+		int type = lua_type(state, index);
+		if (type != LUA_TTABLE && type != LUA_TUSERDATA && type != LUA_TFUNCTION)
+			luaL_argerror(state, index, "Expected table, userdata or function");
+	}
 
 	inline
 	void operator ()() const {