Examples of LuaFunction


Examples of org.luaj.vm2.LuaFunction

            LuaC.install();
            LuaTable environment = LuaValue.tableOf();

            environment.set("animation", new AnimationFunction());

            LuaFunction code = LoadState.load(new FileInputStream(spriteFile),
                spriteFile.getName(), environment);
            code.call();
        }
        catch (IOException ex) {
            throw new SpriteException(ex.getMessage());
        }
        catch (LuaError ex) {
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

    }

    private void doTest( String script ) {
      try {
          InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
      LuaFunction c = LuaC.instance.load( is, "script", _G );
      c.call();
      } catch ( Exception e ) {
        fail("i/o exception: "+e );
      }
    }
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

  }
 
  public LuaFunction load(String classname) {
    try {
      Class c = loadClass( classname );
      LuaFunction v = (LuaFunction) c.newInstance();
      v.setfenv(env);
      return v;
    } catch ( Exception e ) {
      e.printStackTrace();
      throw new IllegalStateException("bad class gen: "+e);
    }
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

            // compile into prototype
            InputStream is = new ByteArrayInputStream(script.getBytes());
            Prototype p = LuaC.instance.compile(is, "script");
           
            // double check script result before dumping
            LuaFunction f = new LuaClosure(p, _G);
            LuaValue r = f.call();
            String actual = r.tojstring();
            assertEquals( expectedPriorDump, actual );
           
            // dump into bytes
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                DumpState.dump(p, baos, stripDebug, numberFormat, littleEndian);
              if ( ! shouldPass )
                fail( "dump should not have succeeded" );
            } catch ( Exception e ) {
              if ( shouldPass )
                fail( "dump threw "+e );
              else
                return;
            }
            byte[] dumped = baos.toByteArray();
           
            // load again using compiler
            is = new ByteArrayInputStream(dumped);
            f = LoadState.load(is, "dumped", _G);
            r = f.call();
            actual = r.tojstring();
            assertEquals( expectedPostDump, actual );

            // write test chunk
            if ( System.getProperty(SAVECHUNKS) != null && script.equals(mixedscript) ) {
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

 
  public CompiledScript compile(Reader reader) throws ScriptException {
    try {
        InputStream ris = new Utf8Encoder(reader);
        try {
          final LuaFunction f = LoadState.load(ris, "script", null);
          if ( f.isclosure() ) {
            // most compiled functions are closures with prototypes
            final Prototype p = f.checkclosure().p;
          return new CompiledScriptImpl() {
            protected LuaFunction newFunctionInstance() {
              return new LuaClosure( p, null );
            }
          };
          } else {
            // when luajc is used, functions are java class instances
            final Class c = f.getClass();
          return new CompiledScriptImpl() {
            protected LuaFunction newFunctionInstance() throws ScriptException {
              try {
                    return (LuaFunction) c.newInstance();
              } catch (Exception e) {
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

    public ScriptEngine getEngine() {
      return LuaScriptEngine.this;
    }
    public Object eval(ScriptContext context) throws ScriptException {
          Bindings b = context.getBindings(ScriptContext.ENGINE_SCOPE);
          LuaFunction f = newFunctionInstance();
          ClientBindings cb = new ClientBindings(b);
          f.setfenv(cb.env);
      Varargs result = f.invoke(LuaValue.NONE);
      cb.copyGlobalsToBindings();
      return result;
    }
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

    if ( name.isnil() ) {
      modinit( module, modname );
    }
   
    // set the environment of the current function
    LuaFunction f = LuaThread.getCallstackFunction(1);
    if ( f == null )
      error("no calling function");
    if ( ! f.isclosure() )
      error("'module' not called from a Lua function");
    f.setfenv(module);
   
    // apply the functions
    for ( int i=2; i<=n; i++ )
      args.arg(i).call( module );
   
View Full Code Here

Examples of org.luaj.vm2.LuaFunction

                   return super.findClass(classname);
                 }
          };
          Class clazz = cl.loadClass(className);
          Object instance = clazz.newInstance();
          LuaFunction value = (LuaFunction) instance;
          value.setfenv( env );
          return value;
        } else {
        }
      } catch ( Exception e ) {
        LuaValue.error("compile task failed: "+e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.