func DLRWS_NS(bcode string, dobind bool, vals map[string]interface{}) (func(*gin.Context), error) {  
	return func(context *gin.Context) {
		L := GetInstance()
		BindContext(L, context)
		if dobind {
			luar.Register(L, "", vals)
		}
		conn, err := upgrader.Upgrade(context.Writer, context.Request, nil)
		if err != nil {
			fmt.Println("Websocket error: " + err.Error())  
		}
		luar.Register(L, "ws", luar.Map{
			"con":           conn,
			"BinaryMessage": websocket.BinaryMessage,
			"TextMessage":   websocket.TextMessage,
			"read": (func() (int, string, error) {
				messageType, p, err := conn.ReadMessage()
				if err != nil {
					return -1, "", err
				}
				return messageType, string(p), nil
			}),
			"read_con": (func(con *websocket.Conn) (int, string, error) {
				messageType, p, err := con.ReadMessage()
				if err != nil {
					return -1, "", err
				}
				return messageType, string(p), nil
			}),
			"send": (func(t int, cnt string) error {
				return conn.WriteMessage(t, []byte(cnt))
			}),
			"send_con": (func(con *websocket.Conn, t int, cnt string) error {
				return con.WriteMessage(t, []byte(cnt))
			}),
			"close": (func() error {
				return conn.Close()
			}),
			"close_con": (func(con *websocket.Conn) error {
				return con.Close()
			}),
		})
		L.LoadBuffer(bcode, len(bcode), "route")
		if L.Pcall(0, 0, 0) != 0 {  
			fmt.Println("Websocket Lua error: " + L.ToString(-1))
			context.Abort()
			return
		}
		conn.Close()
		L.Close()
	}, nil
}
DLRWS_NS does the same as the first one, but for websockets.
package middleware
import (
	"bufio"
	"errors"
	"fmt"
	"net/http"
	"sync"
	"time"
	"github.com/DeedleFake/Go-PhysicsFS/physfs"
	"github.com/carbonsrv/carbon/modules/glue"
	"github.com/carbonsrv/carbon/modules/helpers"
	"github.com/carbonsrv/carbon/modules/scheduler"
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
	"github.com/pmylund/go-cache"
	"github.com/vifino/golua/lua"
	"github.com/vifino/luar"
)
var kvstore *cache.Cache
var cbc *cache.Cache
var cfe *cache.Cache
var LDumper *lua.State
func cacheDump(file string) (string, error, bool) {
	data_tmp, found := cbc.Get(file)
	if found == false {
		data, err := fileRead(file)
		if err != nil {
			return "", err, false
		}
		res, err := bcdump(data)
		if err != nil {
			return "", err, true
		}
		cbc.Set(file, res, cache.DefaultExpiration)
		return res, nil, false
	}
	return data_tmp.(string), nil, false
}
func bcdump(data string) (string, error) {
	if LDumper.LoadString(data) != 0 {
		return "", errors.New(LDumper.ToString(-1))
	}
	defer LDumper.Pop(1)
	return LDumper.FDump(), nil
}
var filesystem http.FileSystem
func fileExists(file string) bool {
	data_tmp, found := cfe.Get(file)
	if found == false {
		exists := physfs.Exists(file)
		cfe.Set(file, exists, cache.DefaultExpiration)
		return exists
	}
	return data_tmp.(bool)
}
func fileRead(file string) (string, error) {
	f, err := filesystem.Open(file)
	defer f.Close()
	if err != nil {
		return "", err
	}
	fi, err := f.Stat()
	if err != nil {
		return "", err
	}
	r := bufio.NewReader(f)
	buf := make([]byte, fi.Size())
	_, err = r.Read(buf)
	if err != nil {
		return "", err
	}
	return string(buf), err
}
var jobs int
var Preloaded chan *lua.State
func newstate() *lua.State {
	L := luar.Init()
	Bind(L, webroot)
	err := L.DoString(glue.MainGlue())
	if err != nil {
		panic(err)
	}
	err = L.DoString(glue.RouteGlue())
	if err != nil {
		panic(err)
	}
	return L
}
func Preloader() {
	Preloaded = make(chan *lua.State, jobs)
	for {
		Preloaded <- newstate()
	}
}
func GetInstance() *lua.State {
	L := <-Preloaded
	return L
}
func Init(j int, cfe_new *cache.Cache, kvstore_new *cache.Cache, root string) {
	webroot = root
	cfe = cfe_new
	kvstore = kvstore_new
	jobs = j
	filesystem = physfs.FileSystem()
	cbc = cache.New(5*time.Minute, 30*time.Second)  
	LDumper = luar.Init()
}
func Lua() func(*gin.Context) {
	return func(context *gin.Context) {
		file := context.Request.URL.Path
		if fileExists(file) {
			L := GetInstance()
			defer scheduler.Add(func() {
				L.Close()
			})
			BindContext(L, context)
			code, err, lerr := cacheDump(file)
			if err != nil {
				if lerr == false {
					context.Next()
					return
				}
				helpers.HTMLString(context, http.StatusInternalServerError, `<html>
<head><title>Syntax Error in `+context.Request.URL.Path+`</title>
<body>
	<h1>Syntax Error in file `+context.Request.URL.Path+`:</h1>
	<pre>`+string(err.Error())+`</pre>
</body>
</html>`)
				context.Abort()
				L.Close()
				return
			}
			L.LoadBuffer(code, len(code), file)  
			if L.Pcall(0, 0, 0) != 0 {           
				helpers.HTMLString(context, http.StatusInternalServerError, `<html>
<head><title>Runtime Error in `+context.Request.URL.Path+`</title>
<body>
	<h1>Runtime Error in file `+context.Request.URL.Path+`:</h1>
	<pre>`+L.ToString(-1)+`</pre>
</body>
</html>`)
				context.Abort()
				L.Close()
				return
			}
			L.Close()
		} else {
			context.Next()
		}
	}
}
func DLR_NS(bcode string, dobind bool, vals map[string]interface{}) (func(*gin.Context), error) {
	return func(context *gin.Context) {
		L := GetInstance()
		if dobind {
			luar.Register(L, "", vals)
		}
		BindContext(L, context)
		L.LoadBuffer(bcode, len(bcode), "route")
		if L.Pcall(0, 0, 0) != 0 {  
			helpers.HTMLString(context, http.StatusInternalServerError, `<html>
<head><title>Runtime Error on `+context.Request.URL.Path+`</title>
<body>
	<h1>Runtime Error in Lua Route on `+context.Request.URL.Path+`:</h1>
	<pre>`+L.ToString(-1)+`</pre>
</body>
</html>`)
			context.Abort()
			L.Close()
			return
		}
		L.Close()
	}, nil
}
func DLR_RUS(bcode string, instances int, dobind bool, vals map[string]interface{}) (func(*gin.Context), error) {  
	pool := sync.Pool{}
	create_func := func() interface{} {
		L := GetInstance()
		if dobind {
			luar.Register(L, "", vals)
		}
		L.LoadBuffer(bcode, len(bcode), "route")
		L.PushValue(-1)
		return L
	}
	for i := 0; i < jobs/2; i++ {
		L := GetInstance()
		if dobind {
			luar.Register(L, "", vals)
		}
		if L.LoadBuffer(bcode, len(bcode), "route") != 0 {
			return func(context *gin.Context) {}, errors.New(L.ToString(-1))
		}
		pool.Put(L)
	}
	pool.New = create_func
	return func(context *gin.Context) {
		L := pool.Get().(*lua.State)
		BindContext(L, context)
		if L.Pcall(0, 0, 0) != 0 {  
			helpers.HTMLString(context, http.StatusInternalServerError, `<html>
<head><title>Runtime Error on `+context.Request.URL.Path+`</title>
<body>
	<h1>Runtime Error in Lua Route on `+context.Request.URL.Path+`:</h1>
	<pre>`+L.ToString(-1)+`</pre>
</body>
</html>`)
			context.Abort()
			L.Close()
			return
		}
		pool.Put(L)
	}, nil
}
var upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin: func(r *http.Request) bool {  
		return true
	},
}