Package org.luaj.vm2

Examples of org.luaj.vm2.LuaFunction


import java.io.IOException;

public class ModuleExecutor {
    public String run(IWikiModel model, String module, String method, Frame frame) throws IOException {
        final Globals globals = getGlobals();
        MwCommon common = new MwCommon(model, globals);
        return common.execute(module, method, frame);
    }
View Full Code Here


        MwCommon common = new MwCommon(model, globals);
        return common.execute(module, method, frame);
    }

    private Globals getGlobals() {
        final Globals globals = JsePlatform.standardGlobals();
//        LuaJC.install(globals);
        return globals;
    }
View Full Code Here

    if (packageLib.loaded.get(packageName).toboolean()) {
      return;
    }
   
    Prototype prototype = LuaCache.loadPackage(packageName, system);
    LuaClosure function = new LuaClosure(prototype, globals);
    function.invoke();
   
    packageLib.loaded.set(packageName, globals);
  }
View Full Code Here

                    defaultAnimationName = animationName; // set first animation as the default one
                }
            }
            catch (SpriteException ex) {
                // Error in the input file.
                throw new LuaError(ex);
            }
            catch (Exception ex) {
                // Error in the editor.
                ex.printStackTrace();
                throw new LuaError(ex);
            }

            return LuaValue.NIL;
        }
View Full Code Here

            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

    }

    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

  }
 
  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

            // 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

 
  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

    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

TOP

Related Classes of org.luaj.vm2.LuaFunction

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.