[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: How to export associative arrays to an embedded lua script?
- From: "linuxfan@..." <linuxfan@...>
- Date: Sat, 10 Oct 2015 08:22:59 +0200 (CEST)
I'm embedding Lua in a pascal program which uses several
tables filled with key/values pairs,
xEnviron['screenwidth'] := 480;
...and so on. Now I
want to expose those tables (about 8 or 9) to Lua, so a script can read
and write values to them. I started with:
(L, xl_getxtable); // my routine to read values
// (__newindex is left out, for the moment)
to create a metatable
which will be associated to the various tables I will export.
every table to export I do this:
This creates a Lua
table named "env". If a script tries to read a value from table env:
lua nicely calls my routine xl_getxtable()
with two arguments - the table and the key.
My problem is that I don't
know how to get the table name lua refers to; while the key is passed
as a string, the table is passed as a lua internal variable which means
nothing to me. I tried to search around in examples, docs, and so on,
but with no success. I only discovered the Registry where, may be, I
can store the table as key and its name as value, so I can later fetch
the name of the table. Probably I will end up using different
xl_getxtable() functions, each one with its hard-coded table name
inside; it would be faster and the tables to export are not so many.
But while am at it, I want to understand.