func (m *Machine) Do(code string, arg interface{}) (string, error, interface{}) { m.StateLock.Lock() defer m.StateLock.Unlock() m.FlushOut() fn, err := m.Lua.LoadString(code) if err != nil { m.InformListeners("err/internal", err.Error()) return "", err, nil } m.Lua.Push(fn) m.Lua.Push(luareflect.ToLua(m.Lua, arg)) if err := m.Lua.PCall(1, 1, nil); err != nil { out := m.FlushOut() m.InformListeners("err/internal", err.Error()) return out, err, nil } out := m.FlushOut() ret := m.Lua.Get(-1) m.Lua.Pop(1) var rv interface{} if ret != nil && ret != lua.LNil { rv = luareflect.DecodeToBasic(ret) } return out, nil, rv }
func tableToMessage(L *lua.LState, t *lua.LTable) sarif.Message { msg := sarif.Message{} msg.Version = tableGetString(t, "sarif") msg.Id = tableGetString(t, "id") msg.Action = tableGetString(t, "action") msg.Source = tableGetString(t, "src") msg.Destination = tableGetString(t, "dest") msg.CorrId = tableGetString(t, "corr") msg.Text = tableGetString(t, "text") p := luareflect.DecodeToBasic(t.RawGetH(lua.LString("p"))) msg.EncodePayload(p) return msg }
func (m *Machine) luaDebug(L *lua.LState) int { out := "" top := L.GetTop() for i := 1; i <= top; i++ { if i > 1 { out += " " } v := L.Get(i) if v.Type() == lua.LTTable { rv := luareflect.DecodeToBasic(v) text, _ := json.MarshalIndent(rv, "", " ") out += string(text) } else { out += v.String() } } m.InformListeners("lua/debug", out) return 0 }