@@ -23,6 +23,7 @@ type Result struct {
2323
2424type Plugin struct {
2525 FileName string `json:"file_name"`
26+ FileContent string `json:"file_content"`
2627 PluginName string `json:"plugin_name"`
2728 PluginVersion string `json:"plugin_version"`
2829 SDKName string `json:"sdk_name"`
@@ -45,17 +46,26 @@ func (p *Plugin) getPluginFilePath() string {
4546 return filepath .Join (pDir , p .FileName )
4647}
4748
48- func (p * Plugin ) Load () error {
49- pluginPath := p .getPluginFilePath ()
50- if ok , _ := gutils .PathIsExist (pluginPath ); ! ok {
51- return fmt .Errorf ("plugin file not found: %s" , pluginPath )
52- }
49+ func (p * Plugin ) LuaDo () error {
5350 if p .result .Lua == nil {
5451 p .result .Lua = lua_global .NewLua ()
5552 }
53+ if p .FileName != "" {
54+ pluginPath := p .getPluginFilePath ()
55+ if ok , _ := gutils .PathIsExist (pluginPath ); ! ok {
56+ return fmt .Errorf ("plugin file not found: %s" , pluginPath )
57+ }
58+ } else if p .FileContent != "" {
59+ if err := p .result .Lua .L .DoString (p .FileContent ); err != nil {
60+ return fmt .Errorf ("failed to load plugin: %s" , err )
61+ }
62+ }
63+ return nil
64+ }
5665
57- if err := p .result .Lua .L .DoFile (pluginPath ); err != nil {
58- return fmt .Errorf ("failed to load plugin file: %s, %s" , pluginPath , err )
66+ func (p * Plugin ) Load () error {
67+ if err := p .LuaDo (); err != nil {
68+ return err
5969 }
6070
6171 L := p .result .Lua .L
0 commit comments