1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-01 12:08:37 -04:00

lua: Add security and account types

This commit is contained in:
2017-01-27 11:04:39 -05:00
parent 806ceb2f5c
commit f3becb7f5c
3 changed files with 307 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"github.com/yuin/gopher-lua"
"log"
"net/http"
"time"
)
@ -10,9 +11,13 @@ import (
//type and value to store user in lua's Context
type key int
const userContextKey key = 0
const (
userContextKey key = iota
accountsContextKey
securitiesContextKey
)
const luaTimeoutSeconds uint = 5 // maximum time a lua request can run for
const luaTimeoutSeconds time.Duration = 5 // maximum time a lua request can run for
func ReportHandler(w http.ResponseWriter, r *http.Request) {
user, err := GetUserFromSession(r)
@ -50,10 +55,25 @@ func ReportHandler(w http.ResponseWriter, r *http.Request) {
panic(err)
}
}
err := L.DoString(`print("Hello World")`)
luaRegisterAccounts(L)
luaRegisterSecurities(L)
err := L.DoString(`accounts = account.get_all()
last_parent = nil
for id, account in pairs(accounts) do
parent = account.parent
print(account, parent, account.security)
if parent then
print(last_parent, parent)
print("parent equals last:", last_parent == parent)
last_parent = parent
end
end
`)
if err != nil {
panic(err)
log.Print("lua:" + err.Error())
}
}
}