getting functions from right table now and reading os and arch in package table
This commit is contained in:
		@@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/go-git/go-git/v6"
 | 
						"github.com/go-git/go-git/v6"
 | 
				
			||||||
 | 
						"github.com/go-git/go-git/v6/plumbing"
 | 
				
			||||||
	"github.com/go-git/go-git/v6/storage/memory"
 | 
						"github.com/go-git/go-git/v6/storage/memory"
 | 
				
			||||||
	"github.com/klauspost/compress/zstd"
 | 
						"github.com/klauspost/compress/zstd"
 | 
				
			||||||
	lua "github.com/yuin/gopher-lua"
 | 
						lua "github.com/yuin/gopher-lua"
 | 
				
			||||||
@@ -46,22 +47,23 @@ func ReadPacket(f []byte) (PacketLua, error) {
 | 
				
			|||||||
	L := lua.NewState()
 | 
						L := lua.NewState()
 | 
				
			||||||
	defer L.Close()
 | 
						defer L.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	osObject := L.GetGlobal("os").(*lua.LTable)
 | 
						//osObject := L.GetGlobal("os").(*lua.LTable)
 | 
				
			||||||
	ioObject := L.GetGlobal("io").(*lua.LTable)
 | 
						//ioObject := L.GetGlobal("io").(*lua.LTable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	L.SetGlobal("os", lua.LNil)
 | 
						//	L.SetGlobal("os", lua.LNil)
 | 
				
			||||||
	L.SetGlobal("io", lua.LNil)
 | 
						//	L.SetGlobal("io", lua.LNil)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := L.DoString(string(f)); err != nil {
 | 
					 | 
				
			||||||
		return PacketLua{}, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	L.SetGlobal("os", osObject)
 | 
					 | 
				
			||||||
	L.SetGlobal("io", ioObject)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	L.SetGlobal("BIN_DIR", lua.LString(cfg.Config.Bin_d))
 | 
						L.SetGlobal("BIN_DIR", lua.LString(cfg.Config.Bin_d))
 | 
				
			||||||
	L.SetGlobal("ARCH", lua.LString(runtime.GOARCH))
 | 
						L.SetGlobal("ARCH", lua.LString(runtime.GOARCH))
 | 
				
			||||||
	L.SetGlobal("OS", lua.LString(runtime.GOOS))
 | 
						L.SetGlobal("OS", lua.LString(runtime.GOOS))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := L.DoString(string(f)); err != nil {
 | 
				
			||||||
 | 
							return PacketLua{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						fmt.Println(string(f))
 | 
				
			||||||
 | 
						//L.SetGlobal("os", osObject)
 | 
				
			||||||
 | 
						//L.SetGlobal("io", ioObject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tableLua := L.Get(-1)
 | 
						tableLua := L.Get(-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if tableLua.Type() != lua.LTTable {
 | 
						if tableLua.Type() != lua.LTTable {
 | 
				
			||||||
@@ -90,10 +92,13 @@ func ReadPacket(f []byte) (PacketLua, error) {
 | 
				
			|||||||
		GitUrl:    getStringFromTable(pkgTable, "git_url"),
 | 
							GitUrl:    getStringFromTable(pkgTable, "git_url"),
 | 
				
			||||||
		GitBranch: getStringFromTable(pkgTable, "git_branch"),
 | 
							GitBranch: getStringFromTable(pkgTable, "git_branch"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Prepare: getFunctionFromTable(pkgTable, "prepare"),
 | 
							Os:           getStringArrayFromTable(L, pkgTable, "os"),
 | 
				
			||||||
		Build:   getFunctionFromTable(pkgTable, "build"),
 | 
							Architetures: getStringArrayFromTable(L, pkgTable, "arch"),
 | 
				
			||||||
		Install: getFunctionFromTable(pkgTable, "install"),
 | 
					
 | 
				
			||||||
		Remove:  getFunctionFromTable(pkgTable, "remove"),
 | 
							Prepare: getFunctionFromTable(table, "prepare"),
 | 
				
			||||||
 | 
							Build:   getFunctionFromTable(table, "build"),
 | 
				
			||||||
 | 
							Install: getFunctionFromTable(table, "install"),
 | 
				
			||||||
 | 
							Remove:  getFunctionFromTable(table, "remove"),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if packetLua.Install == nil || packetLua.Remove == nil {
 | 
						if packetLua.Install == nil || packetLua.Remove == nil {
 | 
				
			||||||
@@ -143,10 +148,10 @@ func ReadPacketFromFile(file io.Reader) (PacketLua, error) {
 | 
				
			|||||||
func GetPackageDotLuaFromRemote(url string, branch string) (PacketLua, error) {
 | 
					func GetPackageDotLuaFromRemote(url string, branch string) (PacketLua, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
 | 
						repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
 | 
				
			||||||
		Depth:        1,
 | 
							Depth:         1,
 | 
				
			||||||
		URL:          url,
 | 
							URL:           url,
 | 
				
			||||||
		SingleBranch: true,
 | 
							SingleBranch:  true,
 | 
				
			||||||
		RemoteName:   "main",
 | 
							ReferenceName: plumbing.ReferenceName("refs/heads/" + branch),
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return PacketLua{}, err
 | 
							return PacketLua{}, err
 | 
				
			||||||
@@ -170,7 +175,5 @@ func GetPackageDotLuaFromRemote(url string, branch string) (PacketLua, error) {
 | 
				
			|||||||
		return PacketLua{}, err
 | 
							return PacketLua{}, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println(content)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return ReadPacket([]byte(content))
 | 
						return ReadPacket([]byte(content))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user