release.sh changes & fixes
[minix3.git] / external / mit / lua / dist / etc / min.c
blob99f6dde5c8b3c8af97ace26985b6ea60c8288da0
1 /* $NetBSD: min.c,v 1.1.1.2 2012/03/15 00:08:14 alnsn Exp $ */
3 /*
4 * min.c -- a minimal Lua interpreter
5 * loads stdin only with minimal error handling.
6 * no interaction, and no standard library, only a "print" function.
7 */
9 #include <stdio.h>
11 #include "lua.h"
12 #include "lauxlib.h"
14 static int print(lua_State *L)
16 int n=lua_gettop(L);
17 int i;
18 for (i=1; i<=n; i++)
20 if (i>1) printf("\t");
21 if (lua_isstring(L,i))
22 printf("%s",lua_tostring(L,i));
23 else if (lua_isnil(L,i))
24 printf("%s","nil");
25 else if (lua_isboolean(L,i))
26 printf("%s",lua_toboolean(L,i) ? "true" : "false");
27 else
28 printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i));
30 printf("\n");
31 return 0;
34 int main(void)
36 lua_State *L=lua_open();
37 lua_register(L,"print",print);
38 if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1));
39 lua_close(L);
40 return 0;