lua-users home
lua-l archive

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


Am Fr., 20. Okt. 2023 um 15:50 Uhr schrieb Roberto Ierusalimschy
<roberto@inf.puc-rio.br>:
>
>For a more generic "C pointer string subtype" in Lua, it probably would
>need some system to release that external memory, e.g. by associating
>the string with a callback to be called when the string is collected.

... are you really sure that this "release of memory" would need to be
done while Lua still running?

Usually this would be done, when Lua machine has finished I think, as
such "external strings" of course by Lua should be assumed to be
static.

(in embedded environment these strings would exist in ROM memory, so
they would just NOT be cleaned up...).

I have no real idea, how these C strings could best be declared in
Lua... in C they clearly must be present already when their pointer is
given to Lua. So maybe somehow like light userdata, just to be used
like static (constant of course) strings in Lua. But I have never used
light userdata so far, so not sure how much sense this idea makes... .
Or C might declare such string names in the registry or some "external
strings" table, and then if a string in Lua is declared with
<external>, Lua looks for the C pointer in this "external strings"
table and uses this to create the TString header.... .