lua-users home
lua-l archive

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

A function in my program takes an associative array as an argument then unpacks the array, converting key-value pairs into variables named after the keys they have the values of.

Except that I cannot figure out how to unpack an associative array like that.
I hear that it can be done with fenv functions, but I can't figure out how.
I tried putting this into the function module.main, but it failed to assign a value to an already-existent nil variable:

local fenv = getfenv(module.main)

for key, value in pairs(arguments) do

   fenv[key] = value


setfenv(module.main, fenv)