Start plugin support and plugin manager

This commit is contained in:
Zachary Yedidia
2019-01-25 22:33:45 -05:00
parent 453e96358a
commit f4a3465a08
5 changed files with 338 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package lua
import (
"bytes"
"errors"
"fmt"
"io"
@@ -28,10 +29,10 @@ func init() {
}
// LoadFile loads a lua file
func LoadFile(module string, file string, data string) error {
pluginDef := "local P = {};" + module + " = P;setmetatable(" + module + ", {__index = _G});setfenv(1, P);"
func LoadFile(module string, file string, data []byte) error {
pluginDef := []byte("module(\"" + module + "\", package.seeall)")
if fn, err := L.Load(strings.NewReader(pluginDef+data), file); err != nil {
if fn, err := L.Load(bytes.NewReader(append(pluginDef, data...)), file); err != nil {
return err
} else {
L.Push(fn)