goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.48k stars 171 forks source link

Embedded use: Provide an object #874

Open aubelsb2 opened 3 years ago

aubelsb2 commented 3 years ago

Before you submit the issue, please provide us following information:

Usage: I'm trying to introduce a variable. I am using "getExecresult()" but it's untested due to an issue providing GOBY_ROOT during test. -- I understand this is designed to be used as a stand alone executable. However I am trying to provide a Ruby-like environment for custom code / extensions to users.

    v, err := vm.New("./", []string{})
    if err != nil {
        return false, err
    }
    instructionSets, err := compiler.CompileToInstructions(code, parser.NormalMode)
    if err != nil {
        return false, err
    }
    dataObject := v.InitObjectFromGoType(data)
    v.GetExecResult().InstanceVariableSet("data", dataObject)
    v.ExecInstructions(instructionSets, "code.rb")
    return v.GetExecResult().Value() == true, nil
st0012 commented 3 years ago

I'm kinda puzzled by the description. can you elaborate more about what's your goal and what's blocking you? thanks