diff options
author | Lua Team <team@lua.org> | 2010-01-08 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2010-01-08 12:00:00 +0000 |
commit | 22912c77c80f8de8f7accd3319c726f7c5349fd3 (patch) | |
tree | caf064ecca31cd2ef1c919c585ee6b3d5e6d25d6 /etc/min.c | |
parent | 300cd56eb905be061aa75bb665549b3b85109bbe (diff) | |
download | lua-github-5.2.0-work1.tar.gz |
Lua 5.2.0-work15.2.0-work1
Diffstat (limited to 'etc/min.c')
-rw-r--r-- | etc/min.c | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -1,39 +1,36 @@ /* * min.c -- a minimal Lua interpreter -* loads stdin only with minimal error handling. -* no interaction, and no standard library, only a "print" function. +* runs one file from the command line or stdin if none given. +* minimal error handling, no traceback, no interaction, no standard library, +* only a "print" function. */ #include <stdio.h> #include "lua.h" #include "lauxlib.h" +#include "lualib.h" static int print(lua_State *L) { int n=lua_gettop(L); int i; + const char *s=""; for (i=1; i<=n; i++) { - if (i>1) printf("\t"); - if (lua_isstring(L,i)) - printf("%s",lua_tostring(L,i)); - else if (lua_isnil(L,i)) - printf("%s","nil"); - else if (lua_isboolean(L,i)) - printf("%s",lua_toboolean(L,i) ? "true" : "false"); - else - printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i)); + printf("%s%s",s,luaL_tolstring(L,i,NULL)); + s="\t"; } printf("\n"); return 0; } -int main(void) +int main(int argc, char *argv[]) { lua_State *L=lua_open(); lua_register(L,"print",print); - if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); + luaL_openlibs(L); + if (luaL_dofile(L,argv[1])!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1)); lua_close(L); return 0; } |