lua-users home
lua-l archive

Re: require in another enviroment

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Dec 26, 2012 at 1:52 PM, Victor Bombi <sonoro@telefonica.net> wrote:
> Is there any way to avoid polluting _G (which has bad side effects for me)
> by using require"sc.synthdefsc"
You could use exactly the same loadstring/setfenv trick to load
sc.synthdefsc; then the supplied environment will contain your
assignments after execution, safely outside _G.
Of course, using loadstring() directly means that you need the full
path to sc.synthdefsc module. You can get this by doing what require()
does, which is look in the semicolon-separated package.path, and keep
a record of whether it's already loaded.
steve d.

AltStyle によって変換されたページ (->オリジナル) /