Example #1
0
        static void dotty(Lua.LuaState L)
        {
            int status;

            Lua.CharPtr oldprogname = progname;
            progname = null;
            while ((status = loadline(L)) != -1)
            {
                if (status == 0)
                {
                    status = docall(L, 0, 0);
                }
                report(L, status);
                if (status == 0 && Lua.lua_gettop(L) > 0)
                {  /* any result to print? */
                    Lua.lua_getglobal(L, "print");
                    Lua.lua_insert(L, 1);
                    if (Lua.lua_pcall(L, Lua.lua_gettop(L) - 1, 0, 0) != 0)
                    {
                        l_message(progname, Lua.lua_pushfstring(L,
                                                                "error calling " + Lua.LUA_QL("print").ToString() + " (%s)",
                                                                Lua.lua_tostring(L, -1)));
                    }
                }
            }
            Lua.lua_settop(L, 0);  /* clear stack */
            Lua.fputs("\n", Lua.stdout);
            Lua.fflush(Lua.stdout);
            progname = oldprogname;
        }
Example #2
0
        static int docall(Lua.LuaState L, int narg, int clear)
        {
            int status;
            int base_ = Lua.lua_gettop(L) - narg; /* function index */

            Lua.lua_pushcfunction(L, traceback);  /* push traceback function */
            Lua.lua_insert(L, base_);             /* put it under chunk and args */
            //signal(SIGINT, laction);
            status = Lua.lua_pcall(L, narg, ((clear != 0) ? 0 : Lua.LUA_MULTRET), base_);
            //signal(SIGINT, SIG_DFL);
            Lua.lua_remove(L, base_);  /* remove traceback function */
            /* force a complete garbage collection in case of errors */
            if (status != 0)
            {
                Lua.lua_gc(L, Lua.LUA_GCCOLLECT, 0);
            }
            return(status);
        }