add table created by lua_bundle to namespace#35
Open
kedorlaomer wants to merge 1 commit into
Open
Conversation
The name is @@@. Therefore, the table doesn't pollute the namespace unless the programmer deliberately uses _ENV["@@@"] for his own values. This facility is helpful for interoperability with luaproc: Every thread could receive some or all values values from this table to access functionality otherwise only available to the main thread.
Owner
|
Please give a code example of using this table with luaproc. |
Author
|
The main thread has a pure lua module -- file module.lua
local M = {}
function M.some_function(arg1, arg2)
-- do something cool
end
return MWe load this module as Now, several of my threads might want to use it, e. g. a function function g()
-- oh no, how do I get access to `module`?
endSo we need to load the string representation of local module_source = _ENV['@@@'].module
g = function() -- this is closed over the environment, can access module_source
local module = load(module_source)()
module.some_function("foo", "bar)
endCaveats:
I am actually using the patched version in an internal project (which I will gladly point to once it's not too embarassing). |
Author
|
For future searches: There's a somewhat ugly solution for C functions. In |
203babe to
c3e1b2e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The name is
@@@.Therefore, the table doesn't pollute the namespaceunless the programmer deliberately uses
_ENV["@@@"]for his ownvalues.
This facility is helpful for interoperability with luaproc:
Every thread can decide to receive some or all values values from this table
and load them to access
functionality otherwise only available to the main thread.
Questions: