示例#1
0
int main (int argc, char *argv[])
{
    int i;
    lua_open();
    lua_pushstring("> ");
    lua_setglobal("_PROMPT");
    lua_userinit();
    if (argc < 2) {  /* no arguments? */
        if (isatty(0)) {
            printf("%s  %s\n", LUA_VERSION, LUA_COPYRIGHT);
            manual_input(1);
        }
        else
            ldo(lua_dofile, NULL);  /* executes stdin as a file */
    }
    else for (i=1; i<argc; i++) {
            if (argv[i][0] == '-') {  /* option? */
                switch (argv[i][1]) {
                case 0:
                    ldo(lua_dofile, NULL);  /* executes stdin as a file */
                    break;
                case 'i':
                    manual_input(1);
                    break;
                case 'q':
                    manual_input(0);
                    break;
                case 'd':
                    lua_setdebug(1);
                    break;
                case 'v':
                    printf("%s  %s\n(written by %s)\n\n",
                           LUA_VERSION, LUA_COPYRIGHT, LUA_AUTHORS);
                    break;
                case 'e':
                    i++;
                    if (ldo(lua_dostring, argv[i]) != 0) {
                        fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
                        return 1;
                    }
                    break;
                default:
                    print_message();
                    exit(1);
                }
            }
            else if (strchr(argv[i], '='))
                assign(argv[i]);
            else {
                int result = ldo(lua_dofile, argv[i]);
                if (result) {
                    if (result == 2) {
                        fprintf(stderr, "lua: cannot execute file ");
                        perror(argv[i]);
                    }
                    exit(1);
                }
            }
        }
#ifdef DEBUG
    lua_close();
#endif
    return 0;
}
示例#2
0
int main ( int argc, char **argv )
{
    IupOpen(&argc, &argv);
#ifndef IUPLUA_NO_GL
    IupGLCanvasOpen();
#endif
#ifndef IUPLUA_NO_CD
    IupControlsOpen();
    IupPPlotOpen();
#endif

    lua_open();

    lua_setdebug(1);

    lua_iolibopen( );
    lua_strlibopen( );
    lua_mathlibopen( );

    iuplua_open( );
    iupkey_open( );
#ifndef IUPLUA_NO_GL
    iupgllua_open();
#endif
#ifndef IUPLUA_NO_CD
    iupcontrolslua_open();
    iup_pplotlua_open();
    cdlua_open();
    cdluaiup_open();
#endif
#ifndef IUPLUA_NO_IM
    iupimlua_open();
    imlua_open();
#endif

    if (argc <= 1)
    {
        if(!iuplua_dofile("console3.lua"))
        {
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/console3_be64.loh"
#else
#include "loh/console3_be32.loh"
#endif
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/console3_le64w.loh"
#else
#include "loh/console3_le64.loh"
#endif
#else
#include "loh/console3.loh"
#endif
#endif
        }
    }
    else
    {
        int ok = 1,
            i  = 1;

        /* Running all .lua given as arguments */
        while(ok & (i < argc))
        {
            ok = iuplua_dofile(argv[i]);
            i++;
        }

        if(!ok)
        {
            return EXIT_FAILURE;
        }
    }

#ifndef IUPLUA_NO_CD
    cdlua_close();
    IupControlsClose();
#endif
    IupClose();

    lua_close();

    return EXIT_SUCCESS;
}