]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | static 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 | ||
32 | int 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 | } |