From 6473f965ca699719b3b9908008f15da48cc2e6f1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 11 Apr 2001 15:39:37 -0300 Subject: new API functions to load (parse?) a chunk without running it. --- lbaselib.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index 4a979814..119d80f7 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.32 2001/04/06 18:25:00 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.33 2001/04/11 14:42:41 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -311,6 +311,7 @@ static int passresults (lua_State *L, int status, int oldtop) { } } + static int luaB_dostring (lua_State *L) { int oldtop = lua_gettop(L); size_t l; @@ -320,6 +321,14 @@ static int luaB_dostring (lua_State *L) { } +static int luaB_loadstring (lua_State *L) { + int oldtop = lua_gettop(L); + size_t l; + const l_char *s = luaL_check_lstr(L, 1, &l); + const l_char *chunkname = luaL_opt_string(L, 2, s); + return passresults(L, lua_loadbuffer(L, s, l, chunkname), oldtop); +} + static int luaB_dofile (lua_State *L) { int oldtop = lua_gettop(L); const l_char *fname = luaL_opt_string(L, 1, NULL); @@ -327,6 +336,14 @@ static int luaB_dofile (lua_State *L) { } +static int luaB_loadfile (lua_State *L) { + int oldtop = lua_gettop(L); + const l_char *fname = luaL_opt_string(L, 1, NULL); + return passresults(L, lua_loadfile(L, fname), oldtop); +} + + + #define LUA_PATH l_s("LUA_PATH") #define LUA_PATH_SEP l_s(";") @@ -753,6 +770,8 @@ static const luaL_reg base_funcs[] = { {l_s("getglobal"), luaB_getglobal}, {l_s("gettagmethod"), luaB_gettagmethod}, {l_s("globals"), luaB_globals}, + {l_s("loadfile"), luaB_loadfile}, + {l_s("loadstring"), luaB_loadstring}, {l_s("newtype"), luaB_newtype}, {l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */ {l_s("next"), luaB_next}, -- cgit v1.2.3-55-g6feb