Giter Site home page Giter Site logo

alexanderschuetz97 / luajfshook Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 32 KB

Hook for Luaj's JseIoLib and other file related functions for more control over how luaj interacts with the file system

License: GNU Lesser General Public License v3.0

Java 100.00%
luaj lua java library

luajfshook's Introduction

LuajFSHook

Hook for Luaj's JseIoLib and other file related functions for more control over how luaj interacts with the file system.
LuajFSHook provides an API that can be used to

  1. Improve interoperability between lua libraries that use the file system
  2. To more easily Sanbox/Jail Luaj's IO lib without having to reimplement the IO Library
  3. Implement a virtual file system to be used by lua that is completely unrelated to the real filesystem.

License

LuajFSHook is released under the GNU Lesser General Public License Version 3.
A copy of the GNU Lesser General Public License Version 3 can be found in the COPYING & COPYING.LESSER files.

Requirements

  • Java 7 or newer
  • LuaJ 3.0.1

Usage:

Maven:

<dependency>
  <groupId>io.github.alexanderschuetz97</groupId>
  <artifactId>luajfshook</artifactId>
  <version>1.0</version>
</dependency>

In Java:

Globals globals = JsePlatform.standardGlobals();
//This will overwrite Globals.finder!
LuajFSHook.install(globals);
//This may be used by your library
LuaFileSystemHandler handler = LuajFSHook.get(globals);

//Example: Lua has a different workdir compared to the jvm

//First we create the "subfolder" which will serve as our new work dir.
new File(new File("."), "luaworkdir").mkdir();

//We get the current work dir that lua uses. This will be equal to "."
LuaPath workDir = handler.getWorkDir().child("luaworkdir");
//Now we change the work dir for lua to the folder we made earlier
handler.setWorkDirectory(workDir.child("luaworkdir"));

//Now we run our lua script the provided example will just create a file.
globals.load(new InputStreamReader(new FileInputStream("test.lua")), "test.lua").call();
//The lua script should have created the file "./luaworkdir/test.txt" 

In test.lua:

local io = require('io')
local file = io.open("test.txt", "w+")
file:write("Hello World")
file:close()

luajfshook's People

Contributors

alexanderschuetz97 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.