Add initial code

This commit is contained in:
Cadey Ratio 2016-04-11 19:18:15 -07:00
parent 5296526fcb
commit c1196f3d1e
4 changed files with 76 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
vendor
bin
pkg
./worm

44
cmd/worm/main.go Normal file
View File

@ -0,0 +1,44 @@
package main
import (
"os"
"runtime"
"git.xeserv.us/xena/worm/script"
"github.com/layeh/gopher-luar"
"github.com/thoj/go-ircevent"
"github.com/yuin/gopher-lua"
)
func main() {
l := script.InitLua()
i := irc.IRC("Cadey", "love")
i.Debug = true
err := i.Connect(os.Getenv("IRC_SERVER"))
if err != nil {
panic(err)
}
i.AddCallback("001", func(e *irc.Event) {
i.Join("#test")
})
i.AddCallback("PRIVMSG", func(e *irc.Event) {
levent := luar.New(l, e)
err := l.CallByParam(lua.P{
Fn: l.GetGlobal("handleMessage"),
NRet: 0,
Protect: true,
}, levent)
if err != nil {
panic(err)
}
})
l.DoFile("./modules/test.lua")
runtime.Goexit()
}

4
modules/test.lua Normal file
View File

@ -0,0 +1,4 @@
function handleMessage(event)
print("hi from lua!")
print(event.connection.server, event.raw)
end

27
script/script.go Normal file
View File

@ -0,0 +1,27 @@
package script
import (
"net/http"
"github.com/cjoudrey/gluahttp"
"github.com/cjoudrey/gluaurl"
"github.com/kohkimakimoto/gluayaml"
ljson "github.com/layeh/gopher-json"
"github.com/layeh/gopher-lfs"
"github.com/yuin/gluare"
"github.com/yuin/gopher-lua"
)
func InitLua() (l *lua.LState) {
l = lua.NewState()
l.PreloadModule("re", gluare.Loader)
l.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
l.PreloadModule("json", ljson.Loader)
l.PreloadModule("yaml", gluayaml.Loader)
l.PreloadModule("url", gluaurl.Loader)
lfs.Preload(l)
return
}