Exemple #1
0
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
}
Exemple #2
0
func messageToTable(L *lua.LState, msg sarif.Message) lua.LValue {
	t := L.NewTable()
	tableSetString(t, "sarif", msg.Version)
	tableSetString(t, "id", msg.Id)
	tableSetString(t, "action", msg.Action)
	tableSetString(t, "src", msg.Source)
	tableSetString(t, "dest", msg.Destination)
	tableSetString(t, "corr", msg.CorrId)
	tableSetString(t, "text", msg.Text)

	p := make(map[string]interface{})
	msg.DecodePayload(&p)
	t.RawSetH(lua.LString("p"), luareflect.ToLua(L, p))
	return t
}