restructure project
Some checks failed
Build / build (push) Failing after 5m21s
Publish Image / publish (push) Failing after 32s
Test / build (push) Failing after 5m8s

This commit is contained in:
Chuck Smith
2024-03-28 16:20:09 -04:00
parent 362138ff2e
commit fc6ceee02c
93 changed files with 479 additions and 194 deletions

37
internal/builtins/ffi.go Normal file
View File

@@ -0,0 +1,37 @@
package builtins
import (
"monkey/internal/object"
"monkey/internal/typing"
)
import (
"fmt"
"plugin"
)
// FFI ...
func FFI(args ...object.Object) object.Object {
if err := typing.Check(
"ffi", args,
typing.ExactArgs(2),
typing.WithTypes(object.STRING_OBJ, object.STRING_OBJ),
); err != nil {
return newError(err.Error())
}
name := args[0].(*object.String).Value
symbol := args[1].(*object.String).Value
p, err := plugin.Open(fmt.Sprintf("%s.so", name))
if err != nil {
return newError("error loading plugin: %s", err)
}
v, err := p.Lookup(symbol)
if err != nil {
return newError("error finding symbol: %s", err)
}
return &object.Builtin{Name: symbol, Fn: v.(object.BuiltinFunction)}
}