Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
install.go: replace lua with ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekingMeaning committed Aug 2, 2020
1 parent bb012a4 commit 352cfa6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
vendor
_dist
libmruby.a
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ TAGS :=
LDFLAGS :=
GOFLAGS :=
BINDIR := $(CURDIR)/bin
VENDORDIR := $(CURDIR)/vendor

# Required for globs to work correctly
SHELL=/bin/bash

.PHONY: all
all: $(BINDIR)/$(BIN_NAME)

$(BINDIR)/$(BIN_NAME):
$(BINDIR)/$(BIN_NAME): libmruby.a
$(GO) build -o $(BINDIR)/$(BIN_NAME) $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(BIN_NAME)

libmruby.a:
go mod vendor
cd vendor/github.com/SeekingMeaning/go-mruby && make libmruby.a
cp vendor/github.com/SeekingMeaning/go-mruby/libmruby.a .

.PHONY: clean
clean:
@rm -rf $(BINDIR)
@rm -rf $(VENDORDIR)

include versioning.mk
16 changes: 10 additions & 6 deletions cmd/gofish/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -17,8 +18,7 @@ import (
"github.com/fishworks/gofish/pkg/home"
"github.com/fishworks/gofish/pkg/ohai"
"github.com/spf13/cobra"
"github.com/yuin/gluamapper"
lua "github.com/yuin/gopher-lua"
ruby "github.com/SeekingMeaning/go-mruby"
)

const installDesc = `
Expand Down Expand Up @@ -112,13 +112,17 @@ func getFood(foodName string) (*gofish.Food, error) {
ohai.Warningf("could not read from install receipt: %v", err)
}

l := lua.NewState()
defer l.Close()
if err := l.DoFile(filepath.Join(home.Rigs(), rig, "Food", fmt.Sprintf("%s.lua", name))); err != nil {
foodBytes, err := ioutil.ReadFile(filepath.Join(home.Rigs(), rig, "Food", fmt.Sprintf("%s.rb", name)))
if err != nil {
return nil, err
}
mrb := ruby.NewMrb()
defer mrb.Close()
if _, err := mrb.LoadString(string(foodBytes)); err != nil {
return nil, err
}
var food gofish.Food
if err := gluamapper.Map(l.GetGlobal(strings.ToLower(reflect.TypeOf(food).Name())).(*lua.LTable), &food); err != nil {
if err := ruby.Decode(&food, mrb.GetGlobalVariable(fmt.Sprintf("$%s", strings.ToLower(reflect.TypeOf(food).Name())))); err != nil {
return nil, err
}
food.Rig = rig
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/Masterminds/semver v1.5.0
github.com/Masterminds/vcs v1.13.1
github.com/SeekingMeaning/go-mruby v0.0.0-20200802182122-533070ae21cd
github.com/bacongobbler/browser v1.1.0
github.com/fatih/color v1.9.0 // indirect
github.com/frankban/quicktest v1.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/Masterminds/vcs v1.13.1 h1:NL3G1X7/7xduQtA2sJLpVpfHTNBALVNSjob6KEjPXNQ=
github.com/Masterminds/vcs v1.13.1/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/SeekingMeaning/go-mruby v0.0.0-20200802182122-533070ae21cd h1:GOxYiqSJ67g+/yh71IyyYpFWIgWi6J1NO03Mq6MVg8g=
github.com/SeekingMeaning/go-mruby v0.0.0-20200802182122-533070ae21cd/go.mod h1:suI7TlsPLIINgZK/SenZ6Ja/PdxNJBIgBYEIfDh54gk=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6 h1:bZ28Hqta7TFAK3Q08CMvv8y3/8ATaEqv2nGoc6yff6c=
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/mitchellh/go-mruby
Submodule go-mruby added at d84828

0 comments on commit 352cfa6

Please sign in to comment.