Skip to content

Function to push 3rd party modules to plugin package #9

@spigell

Description

@spigell

Greetings. Let's assume we have any golang package for glua-libs in somewhere outside of this repo. For example, ssh - https://github.com/spigell/luscheduler/tree/master/libs/ssh. There is no big deal to add glua-libs and custom resources to project, but if we will use plugin package with 3rd party modules inside then it seems to not loading.

local plugin = require("plugin")

local plugin_body = [[
    local time = require("time")
    local chef = require("chef")
    local cron = require("ssh")

    local i = 1
    print(i)
    time.sleep(2)
]]

local string_plugin = plugin.do_string(plugin_body)
string_plugin:run()

time.sleep(1)
if file_plugin:is_running() then
  print("RUNNING")
else
  print("NOT RUNNING")
  print(string_plugin:error())
end

NOT RUNNING
<string>:3: module ssh not found:
	no field package.preload['ssh']
	stat ./ssh.lua: no such file or directory
	stat /usr/local/share/lua/5.1/ssh.lua: no such file or directory
	stat /usr/local/share/lua/5.1/ssh/init.lua: no such file or directory, 
stack traceback:
	[G]: in function 'require'
	<string>:3: in main chunk
	[G]: ?

In plugin package creates a new Lua state with only static list of modules - https://github.com/vadv/gopher-lua-libs/blob/master/plugin/api.go#L75
Is there any change add modules to preload table in the state?

Loader returned by require contains only Lua table with methods without metadata and do not fit for PreloadModules function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions