diff --git a/date_lua.go b/date_lua.go index bbb57ff..b24a594 100644 --- a/date_lua.go +++ b/date_lua.go @@ -13,6 +13,7 @@ func luaRegisterDates(L *lua.LState) { mt := L.NewTypeMetatable(luaDateTypeName) L.SetGlobal("date", mt) L.SetField(mt, "new", L.NewFunction(luaDateNew)) + L.SetField(mt, "now", L.NewFunction(luaDateNow)) L.SetField(mt, "__tostring", L.NewFunction(luaDate__tostring)) L.SetField(mt, "__eq", L.NewFunction(luaDate__eq)) L.SetField(mt, "__lt", L.NewFunction(luaDate__lt)) @@ -85,6 +86,13 @@ func luaDateNew(L *lua.LState) int { return 1 } +func luaDateNow(L *lua.LState) int { + now := time.Now() + date := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) + L.Push(TimeToLua(L, &date)) + return 1 +} + func luaDate__tostring(L *lua.LState) int { a := luaCheckTime(L, 1)