seqlua
view seqlua_c_example.c @ 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"
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 | 45855c3e5cb8 |
children | 92ce3958aca7 |
line source
1 #include <lua.h>
2 #include <lauxlib.h>
3 #include <seqlualib.h>
4 #include <stdio.h>
6 int seqlua_c_example_printcsv(lua_State *L) {
7 seqlua_Iterator iter;
8 seqlua_iterloop(L, &iter, SEQLUA_MODE_CALL, 1) {
9 if (seqlua_itercount(&iter) > 1) fputs(",", stdout);
10 fputs(luaL_tolstring(L, -1, NULL), stdout);
11 // two values need to be popped (the value pushed by
12 // seqlua_iternext and the value pushed by luaL_tolstring)
13 lua_pop(L, 2);
14 }
15 fputs("\n", stdout);
16 return 0;
17 }
19 int luaopen_seqlua_c_example(lua_State *L) {
20 lua_pushcfunction(L, seqlua_c_example_printcsv);
21 lua_setglobal(L, "printcsv");
22 return 0;
23 }