seqlua

view seqlua_c_example.c @ 22:50c6388d4963

Added TODO to README: iterator triplet approach doesn't work
author jbe
date Thu Aug 21 13:04:45 2014 +0200 (2014-08-21)
parents 144f0bddee2b
children 29792283522f
line source
1 #include <lua.h>
2 #include <lauxlib.h>
3 #include "seqlualib.h"
4 #include <stdio.h>
6 static int seqlua_c_example_printcsv(lua_State *L) {
7 seqlua_Iterator iter;
8 seqlua_iterloop(L, &iter, 1) {
9 if (seqlua_itercount(&iter) > 1) fputs(",", stdout);
10 fputs(luaL_tolstring(L, -1, NULL), stdout);
11 lua_pop(L, 1); // pop value that luaL_tolstring pushed onto stack
12 }
13 fputs("\n", stdout);
14 return 0;
15 }
17 static int seqlua_c_example_printthree(lua_State *L) {
18 int i;
19 seqlua_iterclosure(L, 1);
20 for (i=0; i<3; i++) {
21 lua_pushvalue(L, 1);
22 lua_call(L, 0, 1);
23 fputs(luaL_tolstring(L, -1, NULL), stdout);
24 lua_pop(L, 1); // pop value that luaL_tolstring pushed onto stack
25 fputs("\n", stdout);
26 }
27 return 0;
28 }
30 int luaopen_seqlua_c_example(lua_State *L) {
31 lua_pushcfunction(L, seqlua_c_example_printcsv);
32 lua_setglobal(L, "printcsv");
33 lua_pushcfunction(L, seqlua_c_example_printthree);
34 lua_setglobal(L, "printthree");
35 return 0;
36 }

Impressum / About Us