lua: Add title, subtitle, axis labels to reports

This commit is contained in:
Aaron Lindsay 2017-02-11 10:12:04 -05:00
parent d2b98c3d4b
commit 9b3e08fa78
2 changed files with 53 additions and 0 deletions

View File

@ -27,6 +27,7 @@ function generate()
accounts = get_accounts()
r = report.new(12)
r:title(year .. " Monthly Expenses")
series_map = account_series_map(accounts, r)
for month=1,12 do

View File

@ -81,6 +81,14 @@ func luaReport__index(L *lua.LState) int {
L.Push(L.NewFunction(luaReportLabel))
case "Series", "series":
L.Push(L.NewFunction(luaReportSeries))
case "Title", "title":
L.Push(L.NewFunction(luaReportTitle))
case "Subtitle", "subtitle":
L.Push(L.NewFunction(luaReportSubtitle))
case "XAxisLabel", "xaxislabel":
L.Push(L.NewFunction(luaReportXAxis))
case "YAxisLabel", "yaxislabel":
L.Push(L.NewFunction(luaReportYAxis))
default:
L.ArgError(2, "unexpected report attribute: "+field)
}
@ -120,6 +128,50 @@ func luaReportSeries(L *lua.LState) int {
return 1
}
func luaReportTitle(L *lua.LState) int {
report := luaCheckReport(L, 1)
if L.GetTop() == 2 {
report.Title = L.CheckString(2)
return 0
}
L.Push(lua.LString(report.Title))
return 1
}
func luaReportSubtitle(L *lua.LState) int {
report := luaCheckReport(L, 1)
if L.GetTop() == 2 {
report.Subtitle = L.CheckString(2)
return 0
}
L.Push(lua.LString(report.Subtitle))
return 1
}
func luaReportXAxis(L *lua.LState) int {
report := luaCheckReport(L, 1)
if L.GetTop() == 2 {
report.XAxisLabel = L.CheckString(2)
return 0
}
L.Push(lua.LString(report.XAxisLabel))
return 1
}
func luaReportYAxis(L *lua.LState) int {
report := luaCheckReport(L, 1)
if L.GetTop() == 2 {
report.YAxisLabel = L.CheckString(2)
return 0
}
L.Push(lua.LString(report.YAxisLabel))
return 1
}
func luaSeries__index(L *lua.LState) int {
field := L.CheckString(2)