robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
8.11k stars 586 forks source link

JS Array inside Struct don't set the value inside of the otto.VM #386

Closed gus2286 closed 1 year ago

gus2286 commented 4 years ago

Hello,

I'm want to say thank you to all of you for making this package, I love it.

I want to ask if you can help me to see what I'm doing wrong with this:

I have a struct with array:

type MessageType struct {
    TypeMessage     string          `json:"TypeMessage"`
    Field           [130]string         `json:"Field"`
}

var MsgOUT MessageType

After that I set the value to be used on the VM:

vm := otto.New()
errSet := vm.Set("MSG_OUT", &MsgOUT)

JS code:

MSG_OUT.TypeMessage = 'something';
MSG_OUT.Field[1] = '60';
MSG_OUT.Field[2] = 'PEPE';

If I make a console.log inside the JS the 'MSG_OUT.TypeMessage' is correct seted, but the array doesn't is still empty 'MSG_OUT.Field[1]'.

What I'm doing wrong?

Thank you very much Cheers