lua-users home
lua-l archive

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


I have need to provide a mapping of "names" to integer values on a reasonably large scale (hundreds of thousands). The name to number mapping is known at the compile time of my host program (C++). My basic naive approach is to generate a lua source file with the mapping in a table and load that script file into the host environment at run-time. This approach has a substantial time cost to it and seems like it would be more or less unnecessary since the data is static, at least for that particular version of the program.


Example:
field = {
   Field1 = 12345,
   Field2 = 45678,
   -- thousands of additional fields and subtables.
}

-- my intended usage. setData is an exposed API function that takes an integer field value and some data to set it to
setData(field.Field1, "abc")


I'm looking for some advice about how I could have this table of mappings available in my lua environment without having to pay the cost of loading the script every time my program runs.

Thank you in advance