Package org.luaj.vm2

Examples of org.luaj.vm2.LuaThread


        return name;
  }
 
  static Varargs _getlocal(Varargs args) {
    int a=1;
    LuaThread thread = args.isthread(a)? args.checkthread(a++): LuaThread.getRunning();
    int level = args.checkint(a++);
    int local = args.checkint(a++);
   
    DebugState ds = getDebugState(thread);
    DebugInfo di = ds.getDebugInfo(level-1);
View Full Code Here


    }
  }

  static Varargs _setlocal(Varargs args) {
    int a=1;
    LuaThread thread = args.isthread(a)? args.checkthread(a++): LuaThread.getRunning();
    int level = args.checkint(a++);
    int local = args.checkint(a++);
    LuaValue value = args.arg(a++);
   
    DebugState ds = getDebugState(thread);
View Full Code Here

    return NIL;
  }

  static LuaValue _traceback(Varargs args) {
    int a=1;
    LuaThread thread = args.isthread(a)? args.checkthread(a++): LuaThread.getRunning();
    String message = args.optjstring(a++, null);
    int level = args.optint(a++,1);
    String tb = DebugLib.traceback(thread, level-1);
    return valueOf(message!=null? message+"\n"+tb: tb);
  }
View Full Code Here

    }
  }

  public static Varargs pcall(LuaValue func, Varargs args, LuaValue errfunc) {
    try {
      LuaThread thread = LuaThread.getRunning();
      LuaValue olderr = thread.err;
      try {
        thread.err = errfunc;
        return varargsOf(LuaValue.TRUE, func.invoke(args));
      } finally {
View Full Code Here

      case INIT: {
        return init();
      }
      case CREATE: {
        final LuaValue func = args.checkfunction(1);
        return new LuaThread(func, LuaThread.getGlobals() );
      }
      case RESUME: {
        final LuaThread t = args.checkthread(1);
        return t.resume( args.subargs(2) );
      }
      case RUNNING: {
        final LuaThread r = LuaThread.getRunning();
        return LuaThread.isMainThread(r)? NIL: r;
      }
      case STATUS: {
        return valueOf( args.checkthread(1).getStatus() );
      }
      case YIELD: {
        final LuaThread r = LuaThread.getRunning();
        if ( LuaThread.isMainThread( r ) )
          error("main thread can't yield");
        return r.yield( args );
      }
      case WRAP: {
        final LuaValue func = args.checkfunction(1);
        final LuaThread thread = new LuaThread(func, func.getfenv());
        CoroutineLib cl = new CoroutineLib();
        cl.setfenv(thread);
        cl.name = "wrapped";
        cl.opcode = WRAPPED;
        return cl;
      }
      case WRAPPED: {
        final LuaThread t = (LuaThread) env;
        final Varargs result = t.resume( args );
        if ( result.arg1().toboolean() ) {
          return result.subargs(2);
        } else {
          error( result.arg(2).tojstring() );
        }
View Full Code Here

   
    final static String LUADIR = "lua";
   
    public static boolean init () {
    String script = LUADIR + "\\sv_init.lua";
        LuaValue _G = JsePlatform.standardGlobals();
        try {
            _G.get("dofile").call(LuaValue.valueOf(script));
           
        } catch (org.luaj.vm2.LuaError ex) {
            Main.ui.commitln("Error: " + ex.getMessage());
            Main.ui.commitln(sutil.ADVICE.REINSTALL.s());
            return true;
View Full Code Here

                }

                Vector<SpriteAnimationDirection> directions = new Vector<SpriteAnimationDirection>();

                // Traverse the directions table.
                LuaValue key = LuaValue.NIL;
                while (true) {

                    Varargs keyValue = directionsTable.next(key);
                    key = keyValue.arg1();
                    if (key.isnil()) {
                        break;
                    }
                    LuaValue directionTable = keyValue.arg(2);

                    int x = directionTable.get("x").checkint();
                    int y = directionTable.get("y").checkint();
                    int frameWidth = directionTable.get("frame_width").checkint();
                    int frameHeight = directionTable.get("frame_height").checkint();
                    int originX = directionTable.get("origin_x").optint(0);
                    int originY = directionTable.get("origin_y").optint(0);
                    int numFrames = directionTable.get("num_frames").optint(1);
                    int numColumns = directionTable.get("num_columns").optint(numFrames);

                    Rectangle firstFrameRectangle = new Rectangle(x, y, frameWidth, frameHeight);

                    try {
                      SpriteAnimationDirection direction =  new SpriteAnimationDirection(
View Full Code Here

        params.put("b", "b_value");
        subject = new Frame(params, null);
    }

    @Test public void testGetAllArguments() {
        LuaValue arguments = subject.getAllArguments();
        assertThat(arguments.length()).isEqualTo(2);
        assertThat(arguments.get(1).toString()).isEqualTo("a_value");
        assertThat(arguments.get(2).toString()).isEqualTo("b_value");
    }
View Full Code Here

        tests    = loadTests();
    }

    public void runTests(RunNotifier notifier)  {
        final int testCount        = tests.get("count").toint();
        final LuaValue provideFunc = tests.get("provide");
        final LuaValue runFunc     = tests.get("run");

        for (int i=1; i<testCount+1; i++) {
            final Varargs provideValue = provideFunc.invoke(valueOf(i));
            final LuaValue name = provideValue.arg(2);
            final String expected = provideValue.arg(3).checkjstring();

            Description testDescription = Description.createTestDescription(getClass(), name.toString());

            if (isIgnored(testDescription)) {
                notifier.fireTestIgnored(testDescription);
                continue;
            }
View Full Code Here

    public String execute(String module, String method, Frame frame) throws IOException {
        String name = module;
        if (!name.startsWith(Importer.MODULE)) {
            name = Importer.MODULE + name;
        }
        LuaValue chunk = globals.load(findModule(module), name, "t", globals).call();
        LuaValue luaFunction = chunk.get(method);
        LuaValue executeFunction = globals.get("mw").get("executeFunction");

        if (luaFunction == null || luaFunction.isnil()) {
            throw new AssertionError("luaFunction is nil");
        }

        try {
            currentFrame = frame;
            return executeFunction.call(luaFunction).tojstring();
        } finally {
            currentFrame = null;
        }
    }
View Full Code Here

TOP

Related Classes of org.luaj.vm2.LuaThread

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.