allow lua stuff and fix it up
This commit is contained in:
parent
12bb8c4936
commit
c583a03f81
@ -13,6 +13,9 @@ assert-go:
|
|||||||
srndv2: assert-go
|
srndv2: assert-go
|
||||||
GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) build -ldflags "-X srnd.GitVersion=-$(shell git rev-parse --short HEAD)" -v
|
GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) build -ldflags "-X srnd.GitVersion=-$(shell git rev-parse --short HEAD)" -v
|
||||||
|
|
||||||
|
srndv2-lua:
|
||||||
|
GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) build -ldflags "-X srnd.GitVersion=-$(shell git rev-parse --short HEAD)" -tags lua -v
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) clean -v
|
GOPATH=$(REPO) GOROOT=$(GOROOT) $(GO) clean -v
|
||||||
|
|
||||||
|
@ -35,15 +35,16 @@ func (l *Lua) GC() {
|
|||||||
// close the interpreter
|
// close the interpreter
|
||||||
// all resources are expunged and no operations can be done after this
|
// all resources are expunged and no operations can be done after this
|
||||||
func (l *Lua) Close() {
|
func (l *Lua) Close() {
|
||||||
|
l.mtx.Lock()
|
||||||
if l.state != nil {
|
if l.state != nil {
|
||||||
C.lua_close(l.state)
|
C.lua_close(l.state)
|
||||||
}
|
}
|
||||||
l.state = nil
|
l.state = nil
|
||||||
|
l.mtx.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lua) LoadFile(fname string) (err error) {
|
func (l *Lua) LoadFile(fname string) (err error) {
|
||||||
cfname := C.CString(fname)
|
cfname := C.CString(fname)
|
||||||
//defer C.free(unsafe.Pointer(cfname))
|
|
||||||
res := C.luaL_loadfilex(l.state, cfname, nil)
|
res := C.luaL_loadfilex(l.state, cfname, nil)
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
res = C.lua_pcallk(l.state, 0, C.LUA_MULTRET, 0, 0, nil)
|
res = C.lua_pcallk(l.state, 0, C.LUA_MULTRET, 0, 0, nil)
|
||||||
@ -54,12 +55,12 @@ func (l *Lua) LoadFile(fname string) (err error) {
|
|||||||
// failed to load file
|
// failed to load file
|
||||||
err = errors.New("failed to load file " + fname)
|
err = errors.New("failed to load file " + fname)
|
||||||
}
|
}
|
||||||
|
C.free(unsafe.Pointer(cfname))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lua) MEMEPosting(prefix, body string) (meme string) {
|
func (l *Lua) MEMEPosting(prefix, body string) (meme string) {
|
||||||
l.mtx.Lock()
|
l.mtx.Lock()
|
||||||
defer l.mtx.Unlock()
|
|
||||||
cf := C.CString(luaFuncName)
|
cf := C.CString(luaFuncName)
|
||||||
C.lua_getglobal(l.state, cf)
|
C.lua_getglobal(l.state, cf)
|
||||||
cp := C.CString(prefix)
|
cp := C.CString(prefix)
|
||||||
@ -74,8 +75,6 @@ func (l *Lua) MEMEPosting(prefix, body string) (meme string) {
|
|||||||
meme = C.GoStringN(cret, C.int(sz))
|
meme = C.GoStringN(cret, C.int(sz))
|
||||||
}
|
}
|
||||||
|
|
||||||
C.lua_settop(l.state, -(1)-1)
|
|
||||||
|
|
||||||
if res != C.LUA_OK {
|
if res != C.LUA_OK {
|
||||||
// error
|
// error
|
||||||
log.Println("lua error:", meme)
|
log.Println("lua error:", meme)
|
||||||
@ -85,6 +84,9 @@ func (l *Lua) MEMEPosting(prefix, body string) (meme string) {
|
|||||||
// free buffers
|
// free buffers
|
||||||
C.free(unsafe.Pointer(cb))
|
C.free(unsafe.Pointer(cb))
|
||||||
C.free(unsafe.Pointer(cp))
|
C.free(unsafe.Pointer(cp))
|
||||||
|
C.free(unsafe.Pointer(cf))
|
||||||
|
l.GC()
|
||||||
|
l.mtx.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +109,6 @@ func extraMemePosting(src, prefix string) string {
|
|||||||
if luaInt == nil {
|
if luaInt == nil {
|
||||||
return src
|
return src
|
||||||
}
|
}
|
||||||
defer luaInt.GC()
|
|
||||||
return luaInt.MEMEPosting(src, prefix)
|
return luaInt.MEMEPosting(src, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ func (self *VarnishCache) poll() {
|
|||||||
for {
|
for {
|
||||||
ent := <-self.threadsRegenChan
|
ent := <-self.threadsRegenChan
|
||||||
self.Regen(ent)
|
self.Regen(ent)
|
||||||
|
self.RegenerateBoard(ent.Newsgroup())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user