Exemplo n.º 1
0
/* Based on lua.c */
static void _rpmluaInteractive(lua_State *L)
/*@globals fileSystem @*/
/*@modifies L, fileSystem @*/
{
    (void) fputs("\n", stdout);
    printf("RPM Interactive %s Interpreter\n", LUA_VERSION);
    for (;;) {
        int rc = 0;

        if (rpmluaReadline(L, "> ") == 0)
            break;
        if (lua_tostring(L, -1)[0] == '=') {
            /*@-evalorder@*/
            (void) lua_pushfstring(L, "print(%s)", lua_tostring(L, -1)+1);
            /*@=evalorder@*/
            lua_remove(L, -2);
        }
        for (;;) {
            /*@-evalorder@*/
            rc = luaL_loadbuffer(L, lua_tostring(L, -1),
                                 lua_strlen(L, -1), "<lua>");
            /*@=evalorder@*/
            if (rc == LUA_ERRSYNTAX &&
                    strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
                if (rpmluaReadline(L, ">> ") == 0)
                    /*@innerbreak@*/ break;
                lua_remove(L, -2); /* Remove error */
                lua_concat(L, 2);
                /*@innercontinue@*/ continue;
            }
            /*@innerbreak@*/ break;
        }
        if (rc == 0)
            rc = lua_pcall(L, 0, 0, 0);
        if (rc != 0) {
            /*@-evalorderuncon@*/
            fprintf(stderr, "%s\n", lua_tostring(L, -1));
            /*@=evalorderuncon@*/
            lua_pop(L, 1);
        }
        lua_pop(L, 1); /* Remove line */
    }
    (void) fputs("\n", stdout);
}
Exemplo n.º 2
0
Arquivo: rpmlua.c Projeto: Tojaj/rpm
/* Based on lua.c */
static void _rpmluaInteractive(lua_State *L)
{
   (void) fputs("\n", stdout);
   printf("RPM Interactive %s Interpreter\n", LUA_VERSION);
   for (;;) {
      int rc = 0;

      if (rpmluaReadline(L, "> ") == 0)
	 break;
      if (lua_tostring(L, -1)[0] == '=') {
	 (void) lua_pushfstring(L, "print(%s)", lua_tostring(L, -1)+1);
	 lua_remove(L, -2);
      }
      for (;;) {
	 rc = luaL_loadbuffer(L, lua_tostring(L, -1),
			      lua_strlen(L, -1), "<lua>");
	 if (rc == LUA_ERRSYNTAX &&
	     strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
	    if (rpmluaReadline(L, ">> ") == 0)
	       break;
	    lua_remove(L, -2); /* Remove error */
	    lua_concat(L, 2);
	    continue;
	 }
	 break;
      }
      if (rc == 0)
	 rc = lua_pcall(L, 0, 0, 0);
      if (rc != 0) {
	 fprintf(stderr, "%s\n", lua_tostring(L, -1));
	 lua_pop(L, 1);
      }
      lua_pop(L, 1); /* Remove line */
   }
   (void) fputs("\n", stdout);
}