mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-27 07:52:28 -05:00
lua: Add ability to query date year, month, day
This commit is contained in:
parent
75fa8ee28a
commit
5c7dc5df4c
19
date_lua.go
19
date_lua.go
@ -14,6 +14,7 @@ func luaRegisterDates(L *lua.LState) {
|
|||||||
L.SetGlobal("date", mt)
|
L.SetGlobal("date", mt)
|
||||||
L.SetField(mt, "new", L.NewFunction(luaDateNew))
|
L.SetField(mt, "new", L.NewFunction(luaDateNew))
|
||||||
L.SetField(mt, "now", L.NewFunction(luaDateNow))
|
L.SetField(mt, "now", L.NewFunction(luaDateNow))
|
||||||
|
L.SetField(mt, "__index", L.NewFunction(luaDate__index))
|
||||||
L.SetField(mt, "__tostring", L.NewFunction(luaDate__tostring))
|
L.SetField(mt, "__tostring", L.NewFunction(luaDate__tostring))
|
||||||
L.SetField(mt, "__eq", L.NewFunction(luaDate__eq))
|
L.SetField(mt, "__eq", L.NewFunction(luaDate__eq))
|
||||||
L.SetField(mt, "__lt", L.NewFunction(luaDate__lt))
|
L.SetField(mt, "__lt", L.NewFunction(luaDate__lt))
|
||||||
@ -93,6 +94,24 @@ func luaDateNow(L *lua.LState) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func luaDate__index(L *lua.LState) int {
|
||||||
|
d := luaCheckTime(L, 1)
|
||||||
|
field := L.CheckString(2)
|
||||||
|
|
||||||
|
switch field {
|
||||||
|
case "Year", "year":
|
||||||
|
L.Push(lua.LNumber(d.Year()))
|
||||||
|
case "Month", "month":
|
||||||
|
L.Push(lua.LNumber(float64(d.Month())))
|
||||||
|
case "Day", "day":
|
||||||
|
L.Push(lua.LNumber(float64(d.Day())))
|
||||||
|
default:
|
||||||
|
L.ArgError(2, "unexpected date attribute: "+field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
func luaDate__tostring(L *lua.LState) int {
|
func luaDate__tostring(L *lua.LState) int {
|
||||||
a := luaCheckTime(L, 1)
|
a := luaCheckTime(L, 1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user