Updated: Null pointer return support

Georgi Chulkov <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hello,

A few months ago I submitted a patch containing a luabind enhancement: 
http://sourceforge.net/mailarchive/forum.php?thread_name=4B615A26.5070102%40mastheadstudios.net&forum_name=luabind-user

Unfortunately the patch contained a rather serious bug. I am attaching a 
new patch, which fixes the problem, and I apologize for any inconvenience.

(Please include me in any replies because I am not subscribed to the list.)

Best,

Georgi Chulkov
Masthead Studios

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
null_pointer_return.patch (text/plain, 1.3 KB)
Index: luabind/detail/make_instance.hpp
===================================================================
--- luabind/detail/make_instance.hpp
+++ luabind/detail/make_instance.hpp
@@ -39,6 +39,11 @@
 template <class T>
 std::pair<class_id, void*> get_dynamic_class(lua_State* L, T* p)
 {
+    if (!p)
+    {
+        return get_dynamic_class_aux(L, p, mpl::false_());
+    }
+
     return get_dynamic_class_aux(L, p, boost::is_polymorphic<T>());
 }
 
Index: luabind/detail/policy.hpp
===================================================================
--- luabind/detail/policy.hpp
+++ luabind/detail/policy.hpp
@@ -288,10 +288,27 @@
 		}
 
 		template<class T>
-		int match(lua_State* L, by_value<T>, int index)
+		int match(lua_State* L, by_value<T> bv, int index)
 		{
-			// special case if we get nil in, try to match the holder type
+			return match(L, bv, index, has_get_pointer<T>());
+		}
+
+		template<class T>
+		int match(lua_State* L, by_value<T> bv, int index, mpl::true_)
+		{
 			if (lua_isnil(L, index))
+			{
+				make_instance(L, T());
+				lua_replace(L, index > 0 ? index : index - 1);
+			}
+
+			return match(L, bv, index, mpl::false_());
+		}
+
+		template<class T>
+		int match(lua_State* L, by_value<T>, int index, mpl::false_)
+		{
+			if (lua_isnil(L, index))
 				return -1;
 
 			object_rep* obj = get_instance(L, index);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.