From f596b46629ff951954765d7f07f141d719b9c134 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 14 Nov 2016 00:21:36 +0100 Subject: [PATCH] Sdk/Lua: Fix Clock() constructor not correctly handling optional arguments --- SDK/src/NDK/LuaBinding_Core.cpp | 35 +++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 4a1e343f4..3108e1a52 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -13,14 +13,37 @@ namespace Ndk void LuaBinding::BindCore() { /*********************************** Nz::Clock **********************************/ - clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t /*argumentCount*/) + clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount) { - int argIndex = 2; - Nz::Int64 startingValue = lua.Check(&argIndex, 0); - bool paused = lua.Check(&argIndex, false); + std::size_t argCount = std::min(argumentCount, 2U); - Nz::PlacementNew(instance, startingValue, paused); - return true; + int argIndex = 2; + switch (argCount) + { + case 0: + Nz::PlacementNew(instance); + return true; + + case 1: + { + Nz::Int64 startingValue = lua.Check(&argIndex, 0); + + Nz::PlacementNew(instance, startingValue); + return true; + } + + case 2: + { + Nz::Int64 startingValue = lua.Check(&argIndex, 0); + bool paused = lua.Check(&argIndex, false); + + Nz::PlacementNew(instance, startingValue, paused); + return true; + } + } + + lua.Error("No matching overload for Clock constructor"); + return false; }); clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);