Esempio n. 1
0
/*---------------------------------------------------------------------*/
static int
pushline(lua_State *L, int firstline)
{
	TRACE_LUA_FUNC_START();

        char buffer[LUA_MAXINPUT];
        char *b = buffer;
        size_t l;
        const char *prmt = get_prompt(L, firstline);
        if (lua_readline(L, b, prmt) == 0) {
		TRACE_LUA_FUNC_END();
                return 0;  /* no input */
	}
        l = strlen(b);
        /* line ends with newline? */
        if (l > 0 && b[l-1] == '\n')
                b[l-1] = '\0';  /* remove it */

        /* first line starts with `=' ? */
        if (firstline && b[0] == '=')
                lua_pushfstring(L, "return %s", b+1);  /* change it to `return' */
        else
                lua_pushstring(L, b);
        lua_freeline(L, b);

	TRACE_LUA_FUNC_END();
        return 1;
}
static int pushline (lua_State *L, int firstline) {
  char buffer[LUA_MAXINPUT];
  char *b = buffer;
  size_t l;
  const char *prmt = get_prompt(L, firstline);
  if (lua_readline(L, b, prmt) == 0)
    return 0;
  l = strlen(b);
  if (l > 0 && b[l-1] == '\n')
    b[l-1] = '\0';
  if (firstline && b[0] == '=')
    lua_pushfstring(L, "return %s", b+1);
  else
    lua_pushstring(L, b);
  lua_freeline(L, b);
  return 1;
}
Esempio n. 3
0
static int pushline (lua_State *L, int firstline) {
  char buffer[LUA_MAXINPUT];
  char *b = buffer;
  size_t l;
  const char *prmt = get_prompt(L, firstline);
  int readstatus = lua_readline(L, b, prmt);
  lua_pop(L, 1);  /* remove result from 'get_prompt' */
  if (readstatus == 0)
    return 0;  /* no input */
  l = strlen(b);
  if (l > 0 && b[l-1] == '\n')  /* line ends with newline? */
    b[l-1] = '\0';  /* remove it */
  if (firstline && b[0] == '=')  /* first line starts with `=' ? */
    lua_pushfstring(L, "return %s", b+1);  /* change it to `return' */
  else
    lua_pushstring(L, b);
  lua_freeline(L, b);
  return 1;
}
Esempio n. 4
0
/*
** Prompt the user, read a line, and push it into the Lua stack.
*/
static int pushline (lua_State *L, int firstline) {
  char buffer[LUA_MAXINPUT];
  char *b = buffer;
  size_t l;
  const char *prmt = get_prompt(L, firstline);
  int readstatus = lua_readline(L, b, prmt);
  if (readstatus == 0)
    return 0;  /* no input (prompt will be popped by caller) */
  lua_pop(L, 1);  /* remove prompt */
  l = strlen(b);
  if (l > 0 && b[l-1] == '\n')  /* line ends with newline? */
    b[--l] = '\0';  /* remove it */
  if (firstline && b[0] == '=')  /* for compatibility with 5.2, ... */
    lua_pushfstring(L, "return %s", b + 1);  /* change '=' to 'return' */
  else
    lua_pushlstring(L, b, l);
  lua_freeline(L, b);
  return 1;
}
Esempio n. 5
0
static int pushline(lua_State *L, int firstline) {
	char buffer[LUA_MAXINPUT];
	char *b = buffer;
	size_t l;

	if (lua_readline(L, b) == 0)
		return 0; 								/* no input */

	l = strlen(b);
	if (l > 0 && b[l - 1] == '\n')				/* line ends with newline? */
		b[l - 1] = '\0';						/* remove it */
	if (firstline && b[0] == '=')							/* first line starts with `=' ? */
		lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
	else
		lua_pushstring(L, b);
	lua_freeline(L, b);

	return 1;
}