Replaced luax_newtype with luax_pushtype (and added luax_rawnewtype for the old functionality of luax_newtype.)

luax_pushtype keeps the object in a weak table and checks the table before creating a new userdata, so it re-uses the object's existing wrapper userdata if it can, whenever the object is pushed to Lua.

This fixes some subtle issues with love objects, where using them as keys in tables would not always work as expected (https://love2d.org/forums/viewtopic.php?f=4&t=39398&p=112388#p112415). It also decreases the amount of new Lua objects created, saving the garbage collector some work.
This commit is contained in:
Alex Szpakowski
2013-08-29 00:40:06 -03:00
parent 526ccb12ad
commit ec9dec6b80
26 changed files with 267 additions and 111 deletions
+2 -2
View File
@@ -90,7 +90,7 @@ int w_newRandomGenerator(lua_State *L)
}
}
luax_newtype(L, "RandomGenerator", MATH_RANDOM_GENERATOR_T, (void *) t);
luax_pushtype(L, "RandomGenerator", MATH_RANDOM_GENERATOR_T, t);
return 1;
}
@@ -128,7 +128,7 @@ int w_newBezierCurve(lua_State *L)
}
BezierCurve *curve = Math::instance.newBezierCurve(points);
luax_newtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, (void *)curve);
luax_pushtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, curve);
return 1;
}