Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure that <code>gettable()</code> copies the value to the Lua stack, I think it copies a reference or pointer of the value... (especially when that value is a table itself, that table 's content is not copied).</p> <p>And given that Lua may do magic processing, I believe your answer is no.</p> <p>Lua being <strong>free software</strong> you can <a href="http://www.lua.org/download.html" rel="nofollow">download</a> it and <strong>look in the source code</strong>. With <code>lua-5.2.0-rc4</code> the <code>lua_gettable</code> function is in file <code>src/lapi.c</code></p> <pre><code>LUA_API void lua_gettable (lua_State *L, int idx) { StkId t; lua_lock(L); t = index2addr(L, idx); api_checkvalidindex(L, t); luaV_gettable(L, t, L-&gt;top - 1, L-&gt;top - 1); lua_unlock(L); } </code></pre> <p>so the actual work is done by <code>luaV_gettable</code> from file <code>src/lvm.c</code> which is </p> <pre><code>void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; for (loop = 0; loop &lt; MAXTAGLOOP; loop++) { const TValue *tm; if (ttistable(t)) { /* `t' is a table? */ Table *h = hvalue(t); const TValue *res = luaH_get(h, key); /* do a primitive get */ if (!ttisnil(res) || /* result is not nil? */ (tm = fasttm(L, h-&gt;metatable, TM_INDEX)) == NULL) { /* or no TM? */ setobj2s(L, val, res); return; } /* else will try the tag method */ } else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) luaG_typeerror(L, t, "index"); if (ttisfunction(tm)) { callTM(L, tm, t, key, val, 1); return; } t = tm; /* else repeat with 'tm' */ } luaG_runerror(L, "loop in gettable"); } </code></pre> <p>so I think the answer is no. However, you could patch or enhance the code. I don't understand why the question bothers you. Only simple data is copied (very quickly), unless magic occurs (and the magic i.e. metatable is an essential part of Lua semantics); aggregate data content is not copied.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload