lua-users home
lua-l archive

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


Hello,

In Lua 5.1 I am doing this to populate keyword_table from global variables defined in sc.synthdefsc. This file, after defining some globals has requires to other files (say require"blabla") from which I also want to get global variables and that need the definitions contained sc.synthdefsc.
---------------sc,synthdef.lua
variable = 1234
require"blabla"
more_things
--------------blabla
variable2 = variable *3
------------------------
If I dont do require"sc.synthdefsc" ( which is polluting _G)
then "blabla" is not getting variable=1234. That means that cant get it form env
and looks in _G instead.

This is the code:

local env = {}
local keyword_table = {}
  require"sc.synthdefsc"
  local f = assert(loadfile(_scscriptsdir.."synthdefsc.lua"))
  setfenv(f, setmetatable(env, {__index = _G}))
  f()
  for index, value in pairs(env) do
           -- put in keyword_table

Is there any way to avoid polluting _G (which has bad side effects for me) by using require"sc.synthdefsc"

Best
Victor Bombi