lua-users home
lua-l archive

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

2015-10-10 20:46 GMT+02:00 <>:

> The best thing I can think of is to create a lua table for every array
> I want to export.
> All the lua tables share the same metatable, and
> hence the same function xl_getxtable().
> Just after creation of a table,
> I store the lua item in a pascal variable. I will end up with
> a few
> variables, each containing the "lua reference" for the just created
> table.

This is not a good idea. Lua does not promise that the reference
stays valid.

> When xl_getxtable() is called from lua, it will find on the lua
> stack the key
> and the table (some kind of pointer), which I can compare
> with the values stored
> in my variables.

The best way of sharing a Pascal array with Lua is userdata.
You can let Lua manage the storage, and use a metatable to
make it look like a table as far as access syntax is concerned.
Or you can let Pascal manage the storage and pass the pointer
to Lua as a light userdata. It is quite safe for Lua to keep Pascal
pointers, but not the other way round.

Are you using Free Pascal? It has a Lua module that various
people have been keeping up to date. See

> It should work, I suppose that
> lua refers to the same table using always the
> same value or pointer -
> don't you think so?

This may be current behaviour in some iomplementations, but it is
not so documented and relying on it is perilous.