diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-03 17:11:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-03 17:11:41 -0300 |
commit | ad7103ea3aed7f40a5cf7055af253b34320134bc (patch) | |
tree | 978a750ba9c4cb990ece1fe6280f3806acbe6fce /lua.c | |
parent | 0079e0f57ce2bd4dc40b9b7c5831c58764a7938f (diff) | |
download | lua-ad7103ea3aed7f40a5cf7055af253b34320134bc.tar.gz lua-ad7103ea3aed7f40a5cf7055af253b34320134bc.tar.bz2 lua-ad7103ea3aed7f40a5cf7055af253b34320134bc.zip |
lua_load* defined in auxlib (and so renamed to luaL_load*)
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.87 2002/05/16 19:09:19 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.88 2002/05/23 19:43:04 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -107,16 +107,23 @@ static void print_usage (void) { | |||
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static int l_panic (lua_State *l) { | ||
111 | (void)l; | ||
112 | fputs("unable to recover; exiting\n", stderr); | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | |||
110 | static void print_version (void) { | 117 | static void print_version (void) { |
111 | printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); | 118 | printf("%.80s %.80s\n", LUA_VERSION, LUA_COPYRIGHT); |
112 | } | 119 | } |
113 | 120 | ||
114 | 121 | ||
115 | static void assign (char *arg) { | 122 | static void assign (const char *arg) { |
116 | char *eq = strchr(arg, '='); | 123 | char *eq = strchr(arg, '='); /* arg is `name=value'; find the `=' */ |
117 | *eq = '\0'; /* spilt `arg' in two strings (name & value) */ | 124 | lua_pushlstring(L, arg, eq-arg); /* push name */ |
118 | lua_pushstring(L, eq+1); | 125 | lua_pushstring(L, eq+1); /* push value */ |
119 | lua_setglobal(L, arg); | 126 | lua_settable(L, LUA_GLOBALSINDEX); /* _G.name = value */ |
120 | } | 127 | } |
121 | 128 | ||
122 | 129 | ||
@@ -158,12 +165,12 @@ static int docall (int status) { | |||
158 | 165 | ||
159 | 166 | ||
160 | static int file_input (const char *name) { | 167 | static int file_input (const char *name) { |
161 | return docall(lua_loadfile(L, name)); | 168 | return docall(luaL_loadfile(L, name)); |
162 | } | 169 | } |
163 | 170 | ||
164 | 171 | ||
165 | static int dostring (const char *s, const char *name) { | 172 | static int dostring (const char *s, const char *name) { |
166 | return docall(lua_loadbuffer(L, s, strlen(s), name)); | 173 | return docall(luaL_loadbuffer(L, s, strlen(s), name)); |
167 | } | 174 | } |
168 | 175 | ||
169 | 176 | ||
@@ -231,7 +238,7 @@ static int load_string (void) { | |||
231 | firstline = 0; | 238 | firstline = 0; |
232 | push_line(buffer); | 239 | push_line(buffer); |
233 | lua_concat(L, lua_gettop(L)); | 240 | lua_concat(L, lua_gettop(L)); |
234 | status = lua_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); | 241 | status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); |
235 | } while (incomplete(status)); /* repeat loop to get rest of `line' */ | 242 | } while (incomplete(status)); /* repeat loop to get rest of `line' */ |
236 | save_line(lua_tostring(L, 1)); | 243 | save_line(lua_tostring(L, 1)); |
237 | lua_remove(L, 1); | 244 | lua_remove(L, 1); |
@@ -363,6 +370,7 @@ int main (int argc, char *argv[]) { | |||
363 | int toclose = 0; | 370 | int toclose = 0; |
364 | (void)argc; /* to avoid warnings */ | 371 | (void)argc; /* to avoid warnings */ |
365 | L = lua_open(); /* create state */ | 372 | L = lua_open(); /* create state */ |
373 | lua_setpanicf(L, l_panic); | ||
366 | LUA_USERINIT(L); /* open libraries */ | 374 | LUA_USERINIT(L); /* open libraries */ |
367 | register_own(argv); /* create own function */ | 375 | register_own(argv); /* create own function */ |
368 | status = handle_luainit(); | 376 | status = handle_luainit(); |