Hi Muraoka-san,
Thanks for the report and the patch. My comments follow below.
> I found a problem and a future concern on if_lua. And I wrote an
> attached patch to fix those. Please check it.
>
>
> Procedure to reproduce the problem is like this:
>
> > let x = { 'v': 123 }
> > echo x
> > => {'v': 123 }
> >
> > lua x1 = vim.eval('x')
> > lua print(x1.v)
> > => 123
> >
> > lua x1.v = 999
> >
> > echo x
> > => {'v': 123}
> >
> > lua x2 = vim.eval('x')
> > lua print(x2.v)
> > => 999
>
> Last printed '999' is not expected, it must be '123'.
Right, good catch. About your patch: wouldn't a simpler solution be to just
avoid checking if the value is interned? That is, something like:
/* e.g., for VAR_LIST: */
listitem_T *li;
int n = 0;
lua_newtable(L);
lua_pushlightuserdata(L, (void *)l);
lua_pushvalue(L, -2);
lua_rawset(L, LUAVIM_ENVIRONINDEX); /* some cache table: cache[l] = table */
for (li - l->lv_first; li != NULL; li = li->li_next)
{
luaV_pushtypval(L, &li->li_tv);
lua_rawseti(L, -2, ++n);
}
If the user is concerned with efficiency, he/she can intern the value manually
and avoid vim.eval() for the value.
> A future concern is LUA_ENVIRONINDEX. LUA_ENVIRONINDEX is removed from
> Lua 5.2 entirely. To support Lua 5.2 we must stop to use
> LUA_ENVIRONINDEX.
My solution is to use a cache table as upvalue, which should be slightly
faster and better contained (not "polluting" the registry). That is, I have
something like
#define LUAVIM_ENVIRONINDEX lua_upvalueindex(1)
> Fortunately, a cause of the problem is confused references in
> LUA_ENVIRONINDEX. So in my patch, I subsititute LUA_REGISTRYINDEX for
> LUA_ENVIRONINDEX, and separate some tables depend on its usage in
> LUA_REGISTRYINDEX.
Thanks. I have a version of if_lua that is Lua 5.1 and 5.2 compatible. I'll
try to merge your patch and submit an updated patch soon.
Cheers,
Luis
--
Computers are useless. They can only give you answers.
-- Pablo Picasso
--
Luis Carvalho (Kozure)
lua -e 'print((("[email protected]"):gsub("(%u+%.)","")))'
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php