Przeglądaj źródła

fix and make few changes to lua

mikymod 12 lat temu
rodzic
commit
3549b1e2f7

+ 4 - 2
engine/lua/LuaEnvironment.cpp

@@ -25,8 +25,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <stdarg.h>
-#include "Assert.h"
+
 #include "LuaEnvironment.h"
+#include "Assert.h"
 #include "StringUtils.h"
 #include "LuaStack.h"
 #include "Device.h"
@@ -44,16 +45,17 @@ CE_EXPORT int luaopen_libcrown(lua_State* /*L*/)
 	load_int_setting(*env);
 	load_float_setting(*env);
 	load_string_setting(*env);
+
 	load_vec2(*env);
 	load_vec3(*env);
 	load_mat4(*env);
 	load_quat(*env);
 	load_math(*env);
+	load_window(*env);
 	load_mouse(*env);
 	load_keyboard(*env);
 	load_accelerometer(*env);
 	load_device(*env);
-	// load_window(*env);
 	load_resource_package(*env);
 
 	return 1;

+ 0 - 1
engine/lua/LuaEnvironment.h

@@ -90,7 +90,6 @@ private:
 	bool					m_is_used;
 };
 
-
 void load_int_setting(LuaEnvironment& env);
 void load_float_setting(LuaEnvironment& env);
 void load_string_setting(LuaEnvironment& env);

+ 3 - 3
engine/lua/LuaMouse.cpp

@@ -133,9 +133,9 @@ void load_mouse(LuaEnvironment& env)
 	env.load_module_function("Mouse", "cursor_relative_xy",		mouse_cursor_relative_xy);
 	env.load_module_function("Mouse", "set_cursor_relative_xy",	mouse_set_cursor_relative_xy);
 
-	env.load_module_enum("Mouse", "LEFT",		MouseButton::LEFT);
-	env.load_module_enum("Mouse", "MIDDLE",		MouseButton::LEFT);
-	env.load_module_enum("Mouse", "RIGHT",		MouseButton::LEFT);
+	env.load_module_enum("Mouse", "LEFT",						MouseButton::LEFT);
+	env.load_module_enum("Mouse", "MIDDLE",						MouseButton::MIDDLE);
+	env.load_module_enum("Mouse", "RIGHT", 						MouseButton::RIGHT);
 }
 
 } // namespace crown

+ 28 - 74
engine/lua/LuaWindow.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Device.h"
 #include "OsWindow.h"
+#include "Device.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
 
@@ -37,7 +37,7 @@ CE_EXPORT int window_show(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// device()->window()->show();
+	device()->window()->show();
 
 	return 0;
 }
@@ -47,7 +47,7 @@ CE_EXPORT int window_hide(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// device()->window()->hide();
+	device()->window()->hide();
 
 	return 0;
 }
@@ -57,15 +57,14 @@ CE_EXPORT int window_get_size(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// uint32_t w, h;
+	uint32_t w, h;
 
-	// device()->window()->get_size(w, h);
+	device()->window()->get_size(w, h);
 
-	// stack.push_uint32(w);
-	// stack.push_uint32(h);
+	stack.push_uint32(w);
+	stack.push_uint32(h);
 
-	// return 2;
-	return 0;
+	return 2;
 }
 
 //-----------------------------------------------------------------------------
@@ -73,15 +72,14 @@ CE_EXPORT int window_get_position(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// uint32_t x, y;
+	uint32_t x, y;
 
-	// device()->window()->get_position(x, y);
+	device()->window()->get_position(x, y);
 
-	// stack.push_uint32(x);
-	// stack.push_uint32(y);
+	stack.push_uint32(x);
+	stack.push_uint32(y);
 
-	// return 2;
-	return 0;
+	return 2;
 }
 
 //-----------------------------------------------------------------------------
@@ -89,10 +87,10 @@ CE_EXPORT int window_resize(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// const int32_t w = stack.get_int(1);
-	// const int32_t h = stack.get_int(2);
+	const int32_t w = stack.get_int(1);
+	const int32_t h = stack.get_int(2);
 
-	// device()->window()->resize(w, h);
+	device()->window()->resize(w, h);
 
 	return 0;
 }
@@ -102,10 +100,10 @@ CE_EXPORT int window_move(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// const int32_t x = stack.get_int(1);
-	// const int32_t y = stack.get_int(2);
+	const int32_t x = stack.get_int(1);
+	const int32_t y = stack.get_int(2);
 
-	// device()->window()->move(x, y);
+	device()->window()->move(x, y);
 
 	return 0;
 }
@@ -113,14 +111,14 @@ CE_EXPORT int window_move(lua_State* L)
 //-----------------------------------------------------------------------------
 CE_EXPORT int window_minimize(lua_State* /*L*/)
 {
-	// device()->window()->minimize();
+	device()->window()->minimize();
 	return 0;
 }
 
 //-----------------------------------------------------------------------------
 CE_EXPORT int window_restore(lua_State* /*L*/)
 {
-	// device()->window()->restore();
+	device()->window()->restore();
 	return 0;
 }
 
@@ -129,7 +127,7 @@ CE_EXPORT int window_is_resizable(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// stack.push_bool(device()->window()->is_resizable());
+	stack.push_bool(device()->window()->is_resizable());
 
 	return 1;
 }
@@ -139,46 +137,7 @@ CE_EXPORT int window_set_resizable(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// device()->window()->set_resizable(stack.get_bool(1));
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_show_cursor(lua_State* L)
-{
-	LuaStack stack(L);
-
-	// device()->window()->show_cursor(stack.get_bool(1));
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_get_cursor_xy(lua_State* L)
-{
-	LuaStack stack(L);
-
-	// int32_t x, y;
-
-	// device()->window()->get_cursor_xy(x, y);
-
-	// stack.push_int32(x);
-	// stack.push_int32(y);
-
-	// return 2;
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_set_cursor_xy(lua_State* L)
-{
-	LuaStack stack(L);
-
-	// const int32_t x = stack.get_int(1);
-	// const int32_t y = stack.get_int(2);
-
-	// device()->window()->set_cursor_xy(x, y);
+	device()->window()->set_resizable(stack.get_bool(1));
 
 	return 0;
 }
@@ -188,13 +147,11 @@ CE_EXPORT int window_title(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// const char* title = device()->window()->title();
-
-	// stack.push_string(title);
+	const char* title = device()->window()->title();
 
-	// return 1;
+	stack.push_string(title);
 
-	return 0;
+	return 1;
 }
 
 //-----------------------------------------------------------------------------
@@ -202,9 +159,9 @@ CE_EXPORT int window_set_title(lua_State* L)
 {
 	LuaStack stack(L);
 
-	// const char* title = stack.get_string(1);
+	const char* title = stack.get_string(1);
 
-	// device()->window()->set_title(title);
+	device()->window()->set_title(title);
 
 	return 0;
 }
@@ -222,9 +179,6 @@ void load_window(LuaEnvironment& env)
 	env.load_module_function("Window", "restore",		window_restore);
 	env.load_module_function("Window", "is_resizable",	window_is_resizable);
 	env.load_module_function("Window", "set_resizable",	window_set_resizable);
-	env.load_module_function("Window", "show_cursor",	window_show_cursor);
-	env.load_module_function("Window", "get_cursor_xy",	window_get_cursor_xy);
-	env.load_module_function("Window", "set_cursor_xy",	window_set_cursor_xy);
 	env.load_module_function("Window", "title",			window_title);
 	env.load_module_function("Window", "set_title",		window_set_title);
 }