Merged luna-gen from upstream and updated tests scripting
authorHarley Laue <losinggeneration@gmail.com>
Mon, 22 Aug 2011 15:13:47 -0500
branchscripting
changeset 160 611dfa42cd91
parent 159 a097f09f7e01
child 161 89f11a855a6a
Merged luna-gen from upstream and updated tests

* Upstream implemented ==, <, & <= (~=, >, & >= 'just work') so that
change was pulled in to our tree.
* Because of that, == was also added to the couple classes which it
was skipped over.
* Updated the example a bit with tests for ~= and ==
* Removed some parts of the class comments that weren't needed anymore.
src/core/scripting/lua/binding/hgecolor.lua
src/core/scripting/lua/binding/hgeresource.lua
src/core/scripting/lua/binding/hgestrings.lua
src/core/scripting/lua/binding/hgevector.lua
src/core/scripting/lua/example/hge_script.lua
src/core/scripting/lua/luna-gen/luna_gen.lua
--- a/src/core/scripting/lua/binding/hgecolor.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/binding/hgecolor.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -30,11 +30,7 @@
 				hgeColorRGB operator*(const hgeColorRGB &c) const;
 				hgeColorRGB & operator-=(const hgeColorRGB &c);
 				hgeColorRGB & operator+=(const hgeColorRGB &c);
-			]],
-				-- Not implemented in luna-gen
--- 				bool operator ==(const hgeColorRGB &c) const;
--- 				bool operator!=(const hgeColorRGB &c) const;
-			[[
+				bool operator ==(const hgeColorRGB &c) const;
 				hgeColorRGB operator/(const float scalar) const;
 				hgeColorRGB operator*(const float scalar) const;
 				hgeColorRGB & operator*=(const float scalar);
@@ -65,10 +61,7 @@
 				hgeColorHSV operator*(const hgeColorHSV &c) const;
 				hgeColorHSV & operator-=(const hgeColorHSV &c);
 				hgeColorHSV & operator+=(const hgeColorHSV &c);
-			]],
--- 				bool operator==(const hgeColorHSV &c) const;
--- 				bool operator!=(const hgeColorHSV &c) const;
-			[[
+				bool operator==(const hgeColorHSV &c) const;
 				hgeColorHSV operator/(const float scalar) const;
 				hgeColorHSV operator*(const float scalar) const;
 				hgeColorHSV & operator*=(const float scalar);
--- a/src/core/scripting/lua/binding/hgeresource.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/binding/hgeresource.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -123,14 +123,6 @@
 	hgeStringTable*		GetStringTable(const char *name, int resgroup=0);
 
 	ResDesc*			res[RESTYPES];
-
-private:
-	hgeResourceManager(const hgeResourceManager &);
-	hgeResourceManager&	operator= (const hgeResourceManager&);
-	void				_remove_all();
-	void				_parse_script(const char *scriptname=0);
-
-	static HGE			*hge;
 };
 
 --]]
--- a/src/core/scripting/lua/binding/hgestrings.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/binding/hgestrings.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -38,9 +38,9 @@
 
 struct NamedString
 {
-	char			name[MAXSTRNAMELENGTH];
-	char			*string;
-	NamedString		*next;
+	char name[MAXSTRNAMELENGTH];
+	char *string;
+	NamedString *next;
 };
 
 /*
@@ -50,17 +50,8 @@
 {
 public:
 	hgeStringTable(const char *filename);
-	~hgeStringTable();
 
-	char			*GetString(const char *name);
-
-private:
-	hgeStringTable(const hgeStringTable &);
-	hgeStringTable&	operator= (const hgeStringTable &);
-
-	NamedString		*strings;
-
-	static HGE		*hge;
+	char *GetString(const char *name);
 };
 
 --]]
\ No newline at end of file
--- a/src/core/scripting/lua/binding/hgevector.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/binding/hgevector.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -20,15 +20,16 @@
 				'float y',
 			},
 			memberFunctions = {[[
-				hgeVector	operator-  ()					const;
-				hgeVector	operator-  (const hgeVector &v) const;
-				hgeVector	operator+  (const hgeVector &v) const;
-				hgeVector&	operator-= (const hgeVector &v);
-				hgeVector&	operator+= (const hgeVector &v);
+				hgeVector operator-() const;
+				hgeVector operator-(const hgeVector &v) const;
+				hgeVector operator+(const hgeVector &v) const;
+				hgeVector& operator-=(const hgeVector &v);
+				hgeVector& operator+=(const hgeVector &v);
 
-				hgeVector	operator/  (const float scalar)	const;
-				hgeVector	operator*  (const float scalar) const;
-				hgeVector&	operator*= (const float scalar);
+				hgeVector operator/(const float scalar) const;
+				hgeVector operator*(const float scalar) const;
+				hgeVector& operator*=(const float scalar);
+				bool operator==(const hgeVector &v) const;
 			]],
 				{ rename = 'dot', 'float Dot(const hgeVector *v) const;' },
 				{ rename = 'length', 'float Length() const;' },
@@ -48,13 +49,6 @@
 -- NOTE: These are all Unbound still
 float InvSqrt(float x);
 
-class hgeVector
-{
-public:
-	bool		operator== (const hgeVector &v)	const;
-	bool		operator!= (const hgeVector &v)	const;
-};
-
 inline hgeVector operator* (const float s, const hgeVector &v);
 inline float	 operator^ (const hgeVector &v, const hgeVector &u);
 inline float	 operator% (const hgeVector &v, const hgeVector &u);
--- a/src/core/scripting/lua/example/hge_script.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/example/hge_script.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -1,7 +1,12 @@
 print("Hello HGE")
 
 function test_bound(expected, real_value)
-	print("should be "..tostring(expected).."::"..tostring(real_value))
+	local r,e = pcall(assert, expected == real_value)
+	if r then
+		print("test succeeded: "..tostring(expected).." == "..tostring(real_value))
+	else
+		print("test failed: ".. e .. " | "..tostring(expected).." ~= "..tostring(real_value))
+	end
 end
 
 function print_vector(v)
@@ -24,6 +29,10 @@
 print_vector(v5)
 print(v5:dot(v4))
 print(v5:length())
+print("testing ==")
+test_bound(false, v5 == v4)
+test_bound(true, v5 ~= v4)
+test_bound(false, true)
 
 print_separator()
 local f = io.open('test_strings', 'w');
--- a/src/core/scripting/lua/luna-gen/luna_gen.lua	Mon Aug 22 13:44:15 2011 -0500
+++ b/src/core/scripting/lua/luna-gen/luna_gen.lua	Mon Aug 22 15:13:47 2011 -0500
@@ -13,7 +13,7 @@
 	gen_lua.string_types={'const%s+char%s*%*', 'std%s*::%s*string', 'TString'} -- string types has to support static conversion  to const char*, and construction from const char*.
 	gen_lua.string_to_cstr={'@'              , '@.c_str()',         '@.ptr()'}
 	gen_lua.string_from_cstr={'@'            , 'std::string(@)',    'TString(@)'}
-	gen_lua.auto_rename={{'rsub', 'operator%s*-='},{'rmod', 'operator%s*%%='},{'radd', 'operator%s*+='},{'rmult', 'operator%s*%*='}, {'rdiv', 'operator%s*/='},{'assign', 'operator%s*='},{'__call','operator%s*%(%s*%)'},{'__div','operator%s*/'},{'__mul','operator%s*%*'},{'__add','operator%s*+'}, {'__sub','operator%s*-'},{'__mod', 'operator%s*%%'},} -- operator()
+	gen_lua.auto_rename={{'__eq','operator%s*=='},{'__le', 'operator%s*<='},{'__lt', 'operator%s*<'},{'rsub', 'operator%s*-='},{'rmod', 'operator%s*%%='},{'radd', 'operator%s*+='},{'rmult', 'operator%s*%*='}, {'rdiv', 'operator%s*/='},{'assign', 'operator%s*='},{'__call','operator%s*%(%s*%)'},{'__div','operator%s*/'},{'__mul','operator%s*%*'},{'__add','operator%s*+'}, {'__sub','operator%s*-'},{'__mod', 'operator%s*%%'},} -- operator()
 	gen_lua.modifiers={'const', '%*', '&','inline','virtual'}
 	gen_lua.single_letter_modifiers={'%*', '&'}
 	gen_lua.enable_type_checking=true  -- even with this option turned off, some type checking that don't affect computation time is still turned on.
@@ -1365,7 +1365,7 @@
 			-- default ctor that does nothing
 			local def=cppclass_name..'* LunaTraits<'..cppclass_name..' >::_bind_ctor(lua_State *L)\n  {'
 			addLine('  '..def)
-			addLine('   std::cout<<"undefined contructor of '..cppclass_name..' called\\n";')
+			addLine('   std::cerr<<"undefined contructor of '..cppclass_name..' called\\n";')
 			addLine('	return NULL;')
 			addLine('  }')
 			addLine('  void LunaTraits<'..cppclass_name..' >::_bind_dtor('..cppclass_name..'* obj){')