seqlua

view seqlualib.h @ 52:3362ec36cb09

Do not automatically assume that functions passed to ipairs are iterators
but require ipairs(func, mode) to have an explicit mode set to "call" or "generator"
author jbe
date Tue Aug 26 21:10:03 2014 +0200 (2014-08-26)
parents 3ff7cec8d3ce
children 92ce3958aca7
line source
1 #include <lua.h>
2 #include <lauxlib.h>
4 typedef struct {
5 lua_State *L;
6 int idx;
7 int itertype;
8 lua_Integer i;
9 } seqlua_Iterator;
11 #define SEQLUA_MODE_NONE 0
12 #define SEQLUA_MODE_CALL 1
13 #define SEQLUA_MODE_GENERATOR 2
15 extern void seqlua_iterinit(lua_State *L, seqlua_Iterator *iter, int mode, int idx);
17 extern int seqlua_iternext(seqlua_Iterator *iter);
19 #define seqlua_iterloop(L, iter, mode, idx) \
20 for ( \
21 seqlua_iterinit((L), (iter), (mode), (idx)); \
22 seqlua_iternext(iter); \
23 )
25 #define seqlua_iterloopauto(L, iter, mode, idx) \
26 for ( \
27 seqlua_iterinit((L), (iter), (mode), (idx)); \
28 seqlua_iternext(iter); \
29 lua_pop((L), 1) \
30 )
32 #define seqlua_itercount(iter) ((iter)->i)

Impressum / About Us