lua-users home
lua-l archive

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


2014-03-01 20:36 GMT+08:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
> these function as API may reduce dll calls, and reduce lua lock operatiosn.
> and to do loop in lua core may faster than do that youself.

Unfortunatelly, this is true for any loop over the API (and is true
for most other APIs, too). Wouldn't we need multi-value versions for
lua_rawgeti, lua_rawseti, lua_gettable, lua_settable, etc.?

(lua_remove and lua_insert, however, due to their non-constant cost,
may be worth considering.)

We are discussing stack operations of Lua API. stack operations is the most frequently used API, we should reduce it's calls. however, table operations are treats as more "expensive" operations. lua_next is intend use in a while loop. so we needn't multi-value version of that functions.

some other API suggest is use return value more often. especially lua_rawget, lua_getfield, lua_gettable, lua_rawgeti, lua_rawgetp. they should return 0 if get nil and push nothing on stack, and return 1 and push value on stack. I have written so many code that do get, and lua_isnil, and lua_pop, use return value may better. now lua_getmetatable use this idiom which make me happy :)

and some talk about table.wipe/clear or other, we may need a lua_cleartable/lua_wipetable if this function added to lua core (I raise my hand for this).

lua_next is indeed a very good API, I love it's design and used same design in my own project (will open source soon).

another suggest is lua_resume, I found that current API interface (narg is uselee when resume a yield coroutine) is very inconvenient in my daily use of coroutine. I had to move stack myself, sometimes a lua_xmove(f->L, L, n); lua_settop(f->L, 0); lua_xmove(L, f->L, n); or make a loop. if Lua can pop stack top values for us (just like the behavior that lua C function returns), things will easier much.

anyway, thanks for attention :) 
 
--
regards,
Xavier Wang.