feat: enhance plugin system with Go helpers and add Modbus plugin

- Register Go helper functions (modbus.crc16, hex.encode/decode,
  util.bytes) into Lua states for Modbus RTU support
- Add plugins/modbus.lua with .modbus read/write commands
- Fix Reload race condition (hold lock across Unload+Load)
- Make App.Close nil-safe for sess
- Restore internal/console/console_test.go

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
JiXieShi
2026-05-24 00:01:22 +08:00
parent 30d6c2bc3c
commit 209ecac2d5
5 changed files with 293 additions and 6 deletions
+7 -5
View File
@@ -57,6 +57,7 @@ func (m *Manager) Load(path string) (string, error) {
}
state := lua.NewState()
registerHelpers(state)
if err = state.DoFile(abs); err != nil {
state.Close()
return "", err
@@ -110,19 +111,20 @@ func (m *Manager) Disable(name string) error {
return nil
}
// Reload reloads a plugin's file.
// Reload reloads a plugin's file atomically.
func (m *Manager) Reload(name string) error {
m.mu.Lock()
p, ok := m.plugins[name]
m.mu.Unlock()
if !ok {
m.mu.Unlock()
return fmt.Errorf("plugin %s not found", name)
}
path := p.Path
if err := m.Unload(name); err != nil {
return err
}
p.L.Close()
delete(m.plugins, name)
m.mu.Unlock()
_, err := m.Load(path)
return err
}