Pārlūkot izejas kodu

lua: use LuaStack::push_args()

Daniele Bartolini 4 mēneši atpakaļ
vecāks
revīzija
fb70f59c41
3 mainītis faili ar 15 papildinājumiem un 12 dzēšanām
  1. 9 9
      src/device/device.cpp
  2. 5 2
      src/lua/lua_environment.cpp
  3. 1 1
      src/lua/lua_environment.h

+ 9 - 9
src/device/device.cpp

@@ -472,24 +472,24 @@ bool Device::frame()
 
 		{
 			const s64 t0 = time::now();
-			LuaStack stack(_lua_environment->L);
-			stack.push_float(dt);
-			_lua_environment->call_global("update", 1);
+			ArgType::Enum arg_types = ArgType::FLOAT;
+			Arg args; args.float_value = dt;
+			_lua_environment->call_global("update", &arg_types, &args, 1);
 			RECORD_FLOAT("lua.update", f32(time::seconds(time::now() - t0)));
 		}
 		{
 			const s64 t0 = time::now();
-			LuaStack stack(_lua_environment->L);
-			stack.push_float(dt);
-			_lua_environment->call_global("render", 1);
+			ArgType::Enum arg_types = ArgType::FLOAT;
+			Arg args; args.float_value = dt;
+			_lua_environment->call_global("render", &arg_types, &args, 1);
 			RECORD_FLOAT("lua.render", f32(time::seconds(time::now() - t0)));
 		}
 
 		if (_bgfx_callback->_screenshot_ready) {
 			_bgfx_callback->_screenshot_ready = 0;
-			LuaStack stack(_lua_environment->L);
-			stack.push_string(_bgfx_callback->_screenshot_path.c_str());
-			_lua_environment->call_global("screenshot", 1);
+			ArgType::Enum arg_types = ArgType::STRING;
+			Arg args; args.string_value = _bgfx_callback->_screenshot_path.c_str();
+			_lua_environment->call_global("screenshot", &arg_types, &args, 1);
 		}
 	}
 

+ 5 - 2
src/lua/lua_environment.cpp

@@ -431,13 +431,16 @@ int LuaEnvironment::call(int narg, int nres)
 	return status;
 }
 
-void LuaEnvironment::call_global(const char *func, int narg, int nres)
+void LuaEnvironment::call_global(const char *func, ArgType::Enum *arg_types, Arg *args, int narg, int nres)
 {
 	int status;
+	LuaStack stack(L);
 	CE_ENSURE(NULL != func);
 
 	lua_getglobal(L, func);
-	lua_insert(L, 1); // Move func to the top of stack
+
+	stack.push_args(arg_types, args, narg);
+
 	status = call(narg, nres);
 	if (status != LUA_OK) {
 		report(L, status);

+ 1 - 1
src/lua/lua_environment.h

@@ -92,7 +92,7 @@ struct LuaEnvironment
 	int call(int narg, int nres);
 
 	/// Calls the global function @a func.
-	void call_global(const char *func, int narg = 0, int nres = 0);
+	void call_global(const char *func, ArgType::Enum *arg_types = NULL, Arg *args = NULL, int narg = 0, int nres = 0);
 
 	///
 	LuaStack get_global(const char *global);