1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-25 23:23:21 -05:00

lua: Add date.now()

This commit is contained in:
Aaron Lindsay 2017-02-11 06:15:36 -05:00
parent 16a8316c70
commit 75fa8ee28a

View File

@ -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)