org.luaj.vm2.Globals.loadfile()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中org.luaj.vm2.Globals.loadfile()方法的一些代码示例,展示了Globals.loadfile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Globals.loadfile()方法的具体详情如下:
包路径:org.luaj.vm2.Globals
类名称:Globals
方法名:loadfile

Globals.loadfile介绍

[英]Convenience function for loading a file that is either binary lua or lua source.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

public static LuaValue runLuaFile(Globals globals, String luafile) {
  LuaValue chunk = globals.load("require 'com.example.import-me';");
  chunk.call();
  chunk = globals.loadfile(luafile);
  return chunk.call();
}

代码示例来源:origin: hsllany/HtmlNative

public Varargs invoke(Varargs args) {
    LuaString name = args.checkstring(1);
    InputStream is = null;
        
    // get package path
    LuaValue path = package_.get(_PATH);
    if ( ! path.isstring() ) 
      return valueOf("package.path is not a string");
  
    // get the searchpath function.
    Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
    
    // Did we get a result?
    if (!v.isstring(1))
      return v.arg(2).tostring();
    LuaString filename = v.arg1().strvalue();
  
    // Try to load the file.
    v = globals.loadfile(filename.tojstring()); 
    if ( v.arg1().isfunction() )
      return LuaValue.varargsOf(v.arg1(), filename);
    
    // report error
    return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
  }
}

代码示例来源:origin: M66B/XPrivacyLua

public Varargs invoke(Varargs args) {
    LuaString name = args.checkstring(1);
    InputStream is = null;
        
    // get package path
    LuaValue path = package_.get(_PATH);
    if ( ! path.isstring() ) 
      return valueOf("package.path is not a string");
  
    // get the searchpath function.
    Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
    
    // Did we get a result?
    if (!v.isstring(1))
      return v.arg(2).tostring();
    LuaString filename = v.arg1().strvalue();
  
    // Try to load the file.
    v = globals.loadfile(filename.tojstring()); 
    if ( v.arg1().isfunction() )
      return LuaValue.varargsOf(v.arg1(), filename);
    
    // report error
    return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
  }
}

相关文章