lua 5.1 and lua 5.2 side-by-side

This commit is contained in:
Enno Rehling 2012-06-26 05:17:11 -07:00
parent cb14492ccd
commit bd34cbd350
1 changed files with 6 additions and 2 deletions

View File

@ -23,13 +23,17 @@
#define LUA_MAXINPUT 512 #define LUA_MAXINPUT 512
#endif #endif
#if LUA_VERSION_NUM >= 502
#define lua_strlen(L, idx) lua_rawlen(L, idx)
#endif
#if defined(LUA_USE_READLINE) #if defined(LUA_USE_READLINE)
#include <stdio.h> #include <stdio.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#define default_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) #define default_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
#define lua_saveline(L,idx) \ #define lua_saveline(L,idx) \
if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \ if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
add_history(lua_tostring(L, idx)); /* add it to history */ add_history(lua_tostring(L, idx)); /* add it to history */
#define lua_freeline(L,b) ((void)L, free(b)) #define lua_freeline(L,b) ((void)L, free(b))
#else #else
@ -194,7 +198,7 @@ static int loadline(lua_State * L)
if (!pushline(L, 1)) if (!pushline(L, 1))
return -1; /* no input */ return -1; /* no input */
for (;;) { /* repeat until gets a complete line */ for (;;) { /* repeat until gets a complete line */
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_rawlen(L, 1), "=stdin"); status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
if (!incomplete(L, status)) if (!incomplete(L, status))
break; /* cannot try to add lines? */ break; /* cannot try to add lines? */
if (!pushline(L, 0)) /* no more input? */ if (!pushline(L, 0)) /* no more input? */