[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: how to call lua scripts from C/C++ without recompiling each time?
- From: virgil@... (Virgil Smith)
- Date: Tue, 2 Sep 2003 09:58:37 -0500
The reason you don't see reasonable up to date documentation is that the
"reference system" was obsoleted in Lua 5.0. Lua.h includes <<<some>>> of
the "reference system" implemented as macros, but the reason they exist by
that name is mainly just some handholding for transitioning 4.0 users.
The point of removing the "reference system" is that you can do what you
need just by holding on to the value in a Lua value/table somewhere. The
"registry" table is provided as a convenience to the C API as a standard
place to put such values.
As a side note, if you planned to do a map from script name to script
reference value from inside C so that you could use the reference to call
the script, then you've built up way more than you needed. Just make a Lua
table using the script names as keys and the scripts themselves (as the
loaded chunks) as the values.
---
The reason that I say that Lua.h includes <<<some>>> of the "reference
system", is that it does not support unlocked references. If you really
want you could easily implement the full Lua 4.0 "reference system" using
two tables inside the registry. One of the tables should be a weak table
(with weak values), the other a normal "strong" table. The weak table would
contain every living "referenced" object. The strong table would contain all
items that have been "locked". The only side note is that if the stored
items are numbers, strings, booleans, or any other type that has value
semantics rather than reference semantics, you will have to look first in
the strong table, and then in the weak table to find them because they might
be garbage collected out of the weak table (userdatas, functions, and other
types with reference semantics won't be garbage collected out of the weak
table if there is a reference to them in the strong table).
-----Original Message-----
Ok, so you're saying I don't need lua_pushref... Looks like lua_getref
also loads the ref onto the stack. I did not get that from reading the
docs at http://www.lua.org/manual/2.4/node19.html.
Is there more up to date documents for lua_ref getref and unref? I
couldn't find mention of these in the 5.0 docs.
thanks