aboutsummaryrefslogtreecommitdiff
path: root/libs/lua/etc/min.c
diff options
context:
space:
mode:
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}