示例#1
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntColumnQuery(L *lua.State) int {
	if (L.GetTop() != 1) && (L.GetTop() != 3) {
		panic(errors.New("Wrong number of arguments to columnq"))
		return 0
	}

	name := L.ToString(1)
	op := ""
	value := ""
	if L.GetTop() == 3 {
		op = L.ToString(2)
		value = L.ToString(3)
		L.Pop(3)
	} else {
		L.Pop(1)
	}

	if name[0] == ':' {
		panic(errors.New("Column name can not start with ':'"))
		return 0
	}

	L.CheckStack(1)
	tl := GetTasklistFromLua(L)

	tl.luaState.PushGoStruct(&SimpleExpr{name, op, value, nil, 0, ""})
	return 1
}
示例#2
0
文件: luaint.go 项目: aarzilli/pooch
func GetTasklistFromLua(L *lua.State) *Tasklist {
	L.CheckStack(1)
	L.GetGlobal(TASKLIST)
	rawptr := L.ToUserdata(-1)
	var ptr **Tasklist = (**Tasklist)(rawptr)
	L.Pop(1)
	return *ptr
}
示例#3
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntShowRet(L *lua.State) int {
	L.CheckStack(2)
	tl := GetTasklistFromLua(L)

	tl.luaFlags.showReturnValue = true

	return 0
}
示例#4
0
文件: luaint.go 项目: aarzilli/pooch
func PushStringVec(L *lua.State, v []string) {
	L.CheckStack(3)
	L.CreateTable(len(v), 0)

	for idx, val := range v {
		SetTableIntString(L, int64(idx+1), val)
	}
}
示例#5
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntWriteCursor(L *lua.State) int {
	Logf(INFO, "Writing cursor")
	L.CheckStack(1)
	tl := GetTasklistFromLua(L)
	luaAssertNotFreeCursor(tl, "writecursor()")
	cursor := GetEntryFromLua(L, CURSOR, "writecursor()")
	tl.Update(cursor, false)
	return 0
}
示例#6
0
文件: luaint.go 项目: aarzilli/pooch
func GetEntryFromLua(L *lua.State, name string, fname string) *Entry {
	L.CheckStack(1)
	L.GetGlobal(name)
	rawptr := L.ToUserdata(-1)
	var ptr **Entry = (**Entry)(rawptr)
	L.Pop(1)
	if ptr == nil {
		panic(errors.New("No cursor set, can not use " + fname))
	}
	return *ptr

}
示例#7
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntPriorityQuery(L *lua.State) int {
	luaAssertArgnum(L, 1, "priorityq()")

	priority := L.ToString(1)

	L.CheckStack(1)
	tl := GetTasklistFromLua(L)

	tl.luaState.PushGoStruct(&SimpleExpr{":priority", "=", priority, nil, ParsePriority(priority), ""})

	return 1
}
示例#8
0
文件: luaint.go 项目: aarzilli/pooch
func PushTime(L *lua.State, t time.Time) {
	L.CheckStack(3)
	L.CreateTable(0, 7)

	SetTableInt(L, "year", int64(t.Year()))
	SetTableInt(L, "month", int64(t.Month()))
	SetTableInt(L, "day", int64(t.Day()))
	SetTableInt(L, "weekday", int64(t.Weekday()))
	SetTableInt(L, "hour", int64(t.Hour()))
	SetTableInt(L, "minute", int64(t.Minute()))
	SetTableInt(L, "second", int64(t.Second()))
}
示例#9
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntStringFunction(L *lua.State, name string, n int, fn func(tl *Tasklist, argv []string) int) int {
	luaAssertArgnum(L, n, name)

	argv := make([]string, 0)

	for i := 1; i <= n; i++ {
		argv = append(argv, L.ToString(i))
	}
	L.Pop(n)
	L.CheckStack(1)
	tl := GetTasklistFromLua(L)
	return fn(tl, argv)
}
示例#10
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntTimestamp(L *lua.State) int {
	luaAssertArgnum(L, 1, "timestamp()")

	if !L.IsTable(-1) {
		panic(errors.New("Argoment of timestamp is not a table"))
		return 0
	}

	L.CheckStack(1)

	t := time.Date(GetTableInt(L, "year"), time.Month(GetTableInt(L, "month")), GetTableInt(L, "day"), GetTableInt(L, "hour"), GetTableInt(L, "minute"), GetTableInt(L, "second"), 0, time.Local)

	L.PushInteger(int64(t.Unix()))
	return 1
}
示例#11
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntNotQuery(L *lua.State) int {
	luaAssertArgnum(L, 1, "Wrong number of arguments to notq")

	L.CheckStack(1)
	tl := GetTasklistFromLua(L)

	clausable := GetQueryObject(tl, -1)
	if clausable == nil {
		panic(errors.New("Wrong argument type to notq only query objects accepted as arguments"))
		return 0
	}

	tl.luaState.PushGoStruct(&NotExpr{clausable})
	return 1

}
示例#12
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntParseDateTime(L *lua.State) int {
	luaAssertArgnum(L, 1, "parsedatetime()")

	L.CheckStack(1)

	input := L.ToString(-1)
	tl := GetTasklistFromLua(L)

	out, _ := ParseDateTime(input, tl.GetTimezone())

	if out != nil {
		L.PushInteger(int64(out.Unix()))
	} else {
		L.PushInteger(0)
	}

	return 1
}
示例#13
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntBoolQuery(L *lua.State, operator, name string) int {
	if L.GetTop() < 2 {
		panic(errors.New("Wrong number of arguments to " + name))
		return 0
	}

	L.CheckStack(1)
	tl := GetTasklistFromLua(L)

	r := &BoolExpr{operator, make([]Clausable, 0)}

	for i := 1; i <= L.GetTop(); i++ {
		clausable := GetQueryObject(tl, i)
		if clausable == nil {
			panic(errors.New("Wrong argument type to " + name + " only query objects accepted as arguments"))
			return 0
		}
		r.subExpr = append(r.subExpr, clausable)
	}

	tl.luaState.PushGoStruct(r)
	return 1
}
示例#14
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntSearch(L *lua.State) int {
	if (L.GetTop() < 1) || (L.GetTop() > 2) {
		panic(errors.New("Wrong number of arguments to search()"))
		return 0
	}

	L.CheckStack(2)
	tl := GetTasklistFromLua(L)

	if !tl.luaFlags.freeCursor {
		panic(errors.New("search() function only available on a free cursor"))
		return 0
	}

	query := L.ToString(1)
	var luaClausable Clausable = nil
	if L.GetTop() == 2 {
		luaClausable = GetQueryObject(tl, 2)
	}

	theselect, _, _, _, _, _, _, perr := tl.ParseSearch(query, luaClausable)
	Must(perr)

	entries, serr := tl.Retrieve(theselect, "", false)
	Must(serr)

	Logf(INFO, "Searching from lua interface <%s> clausable: <%v> yields %d results\n", query, luaClausable, len(entries))

	r := []string{}
	for _, entry := range entries {
		r = append(r, entry.Id())
	}

	PushStringVec(L, r)
	return 1
}
示例#15
0
文件: luaint.go 项目: aarzilli/pooch
func LuaIntVisit(L *lua.State) int {
	L.CheckStack(1)
	tl := GetTasklistFromLua(L)
	luaAssertNotFreeCursor(tl, "visit()")
	id := L.ToString(1)
	Logf(DEBUG, "Lua visiting: <%s>\n", id)
	var error interface{} = nil

	{
		defer func() {
			if rerr := recover(); rerr != nil {
				error = rerr
			}
		}()
		cursor := tl.Get(id)
		tl.SetEntryInLua(CURSOR, cursor)
	}

	if error != nil {
		tl.SetEntryInLua(CURSOR, nil)
	}

	return 0
}