aboutsummaryrefslogtreecommitdiff
path: root/libs/lua/etc/min.c
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-16 10:58:21 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-16 23:10:16 (GMT)
commit1061e5282d7deeb3e15a5d1c9bc03e0759b1f2cd (patch)
tree82c384e4afb8e8eefec15e7481c9f5648071ee33 /libs/lua/etc/min.c
parentfe2d9476d5025048f45ea7535a8c7412daa50438 (diff)
downloadfluxbox_pavel-1061e5282d7deeb3e15a5d1c9bc03e0759b1f2cd.zip
fluxbox_pavel-1061e5282d7deeb3e15a5d1c9bc03e0759b1f2cd.tar.bz2
Add lua as an internal library in libs/lua
Diffstat (limited to 'libs/lua/etc/min.c')
-rw-r--r--libs/lua/etc/min.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libs/lua/etc/min.c b/libs/lua/etc/min.c
new file mode 100644
index 0000000..6a85a4d
--- /dev/null
+++ b/libs/lua/etc/min.c
@@ -0,0 +1,39 @@
1/*
2* min.c -- a minimal Lua interpreter
3* loads stdin only with minimal error handling.
4* no interaction, and no standard library, only a "print" function.
5*/
6
7#include <stdio.h>
8
9#include "lua.h"
10#include "lauxlib.h"
11
12static int print(lua_State *L)
13{
14 int n=lua_gettop(L);
15 int i;
16 for (i=1; i<=n; i++)
17 {
18 if (i>1) printf("\t");
19 if (lua_isstring(L,i))
20 printf("%s",lua_tostring(L,i));
21 else if (lua_isnil(L,i))
22 printf("%s","nil");
23 else if (lua_isboolean(L,i))
24 printf("%s",lua_toboolean(L,i) ? "true" : "false");
25 else
26 printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i));
27 }
28 printf("\n");
29 return 0;
30}
31
32int main(void)
33{
34 lua_State *L=lua_open();
35 lua_register(L,"print",print);
36 if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1));
37 lua_close(L);
38 return 0;
39}