[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: C implementation of Generic For?
- From: "King, Mike" <MKing@...>
- Date: Thu, 5 Aug 2010 17:39:18 -0400
How would one write the following Lua code using the Lua C interface? I have written a function that behaves like ipairs and pairs. I would like to use it from the C interface but I'm not sure how to accomplish it.
### Lua ###
for a,b in func() do
print(a,b)
end
### C ###
// is this the equivalent code?
lua_getglobal(L, "func");
lua_call(L, 0, 3);
for (;;) {
lua_pushvalue(L, -3);
lua_pushvalue(L, -3);
lua_pushvalue(L, -3);
lua_call(L, 2, 1);
if (lua_isnil(L, -1)) break;
lua_getglobal(L, "print");
lua_insert(L, lua_gettop(L)-2);
lua_call(L, 2, 0);
}
CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is confidential or proprietary to K&L Microwave, Inc. Any unauthorized review, use, disclosure or distribution is prohibited.
If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and, if so, cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail and delete or destroy all copies of this e-mail message and/or any file attachment(s).