Skip to content

Commit

Permalink
Rename ExternalClass to NewExternalClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Apr 21, 2020
1 parent 79042ed commit f5b0c8b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion native/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type (
)

func init() {
vm.RegisterExternalClass("db", vm.ExternalClass("DB", "db.gb",
vm.RegisterExternalClass("db", vm.NewExternalClassLoader("DB", "db.gb",
// class methods
map[string]vm.Method{
"get_connection": getConnection,
Expand Down
2 changes: 1 addition & 1 deletion native/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
)

func init() {
vm.RegisterExternalClass("plugin", vm.ExternalClass("Plugin", "plugin.gb",
vm.RegisterExternalClass("plugin", vm.NewExternalClassLoader("Plugin", "plugin.gb",
// class methods
map[string]Method{
"new": newPlugin,
Expand Down
2 changes: 1 addition & 1 deletion native/result/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func init() {
vm.RegisterExternalClass(
"result", vm.ExternalClass(
"result", vm.NewExternalClassLoader(
"Result",
"result.gb",
map[string]vm.Method{
Expand Down
2 changes: 1 addition & 1 deletion native/ripper/ripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func tokenize(receiver Object, sourceLine int, t *Thread, args []Object) Object

// Internal functions ===================================================
func init() {
vm.RegisterExternalClass("ripper", vm.ExternalClass("Ripper", "ripper.gb",
vm.RegisterExternalClass("ripper", vm.NewExternalClassLoader("Ripper", "ripper.gb",
// class methods
map[string]vm.Method{
"instruction": instruction,
Expand Down
10 changes: 5 additions & 5 deletions vm/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ func buildMethods(m map[string]Method) []*BuiltinMethodObject {
return out
}

// ExternalClass helps define external go classes
func ExternalClass(name, path string, classMethods, instanceMethods map[string]Method) ClassLoader {
// NewExternalClassLoader helps define external go classes by generating a class loader function
func NewExternalClassLoader(className, libPath string, classMethods, instanceMethods map[string]Method) ClassLoader {
return func(v *VM) error {
pg := v.initializeClass(name)
pg := v.initializeClass(className)
pg.setBuiltinMethods(buildMethods(classMethods), true)
pg.setBuiltinMethods(buildMethods(instanceMethods), false)
v.objectClass.setClassConstant(pg)

if path == "" {
if libPath == "" {
return nil
}

return v.mainThread.execGobyLib(path)
return v.mainThread.execGobyLib(libPath)
}
}

Expand Down

0 comments on commit f5b0c8b

Please sign in to comment.