{"id":21944978,"url":"https://github.com/alexanderschuetz97/luajlfs","last_synced_at":"2026-05-17T02:11:51.048Z","repository":{"id":57732308,"uuid":"436395132","full_name":"AlexanderSchuetz97/LuajLFS","owner":"AlexanderSchuetz97","description":"LuajLFS is a port of the C based LuaFileSystem library to luaj.","archived":false,"fork":false,"pushed_at":"2022-03-25T03:39:21.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T17:47:04.437Z","etag":null,"topics":["lua","luafilesystem","luaj"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexanderSchuetz97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-08T21:20:30.000Z","updated_at":"2021-12-08T22:05:00.000Z","dependencies_parsed_at":"2022-08-31T03:31:40.623Z","dependency_job_id":null,"html_url":"https://github.com/AlexanderSchuetz97/LuajLFS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderSchuetz97%2FLuajLFS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderSchuetz97%2FLuajLFS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderSchuetz97%2FLuajLFS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderSchuetz97%2FLuajLFS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexanderSchuetz97","download_url":"https://codeload.github.com/AlexanderSchuetz97/LuajLFS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244982058,"owners_count":20542300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","luafilesystem","luaj"],"created_at":"2024-11-29T04:17:31.381Z","updated_at":"2026-05-17T02:11:50.982Z","avatar_url":"https://github.com/AlexanderSchuetz97.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LuajLFS\nLuajLFS is a port of the C based LuaFileSystem library to luaj.\n\nLuajLFS tries to use the same OS syscalls that C based LuaFileSystem uses whenever possible.\nOn supported operating systems compatibility should be very high.\n\nFor more information on LuaFileSystem and a documentation of the Lua API see:\nhttps://github.com/keplerproject/luafilesystem/\n\n## License\nLuajLFS is released under the GNU Lesser General Public License Version 3. \u003cbr\u003e\nA copy of the GNU Lesser General Public License Version 3 can be found in the COPYING \u0026 COPYING.LESSER files.\u003cbr\u003e\n\n## Requirements\n* Java 7 or newer\n* LuaJ 3.0.1\n\n## Usage:\nMaven:\n````\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.alexanderschuetz97\u003c/groupId\u003e\n  \u003cartifactId\u003eLuajLFS\u003c/artifactId\u003e\n  \u003cversion\u003e1.3\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\nIn Java:\n````\nGlobals globals = JsePlatform.standardGlobals();\nglobals.load(new LuajLFSLib());\n//.... (Standart LuaJ from this point)\nglobals.load(new InputStreamReader(new FileInputStream(\"test.lua\")), \"test.lua\").call();\n````\nIn test.lua:\n````\nlocal lfs = require('lfs')\nfor file in lfs.dir(\".\") do\n    print(file)\nend\n````\n## Important Implementation Details\n#### IOLib\nLuajLFS uses LuajFSHook to access the filesystem. (see https://github.com/AlexanderSchuetz97/LuajFSHook)\n\u003cbr\u003eTLDR:\u003cbr\u003e\nIf LuajFSHook is not loaded prior to calling 'globals.load(new LuajLFSLib())' then\nLuajLFS will load LuajFSHook and this will overwrite the io table and some entries in the os table.\nIf you use a custom IOLib or custom os functions you will have to load LuajFSHook before loading your libraries.\n\n#### chdir \u0026 relative paths\nSince LuaJ supports running multiple concurrent Lua environments that should NOT affect each other calling\nthe native methods \"chdir\" or \"SetCurrentDirectory\" would break this principle since all Lua Environments would \naffect each other's work directory. Not to mention that this is heavily discouraged by the JVM specification. \nTo solve this the work directory is purely virtual and tracked inside a variable in java. \nThis means if Lua changes the work directory and calls a Java method (via luajava for example) that then does new File(\".\") then said File Object\nwould not be in the work directory that lua set, but rather in the work directory that the entire JVM uses. \nSame goes for any calls made to C based JNI libraries.\n\nIf you have any other JavaLib that relies on relative paths consider using LuajFSHook \nto resolve paths and modify/get the work directory.\n\n#### File locking\nAs mentioned before LuaJ allows for multiple concurrent Lua Environments. Unfortunately the OS/JVM that manages\nFileLocks is unaware of this and will assign the locks to the JVM Process. This means all locks on files are\nalways shared between all Lua Environments running in the same JVM Process.\n\n#### Windows file locking\nC based LuaFileSystem uses the _locking syscall to lock files. (lua method: lfs.lock) \nUnfortunately windows has 2 different methods of interacting with files:\nHANDLE's and FD's. C based lua uses FD's and the JVM (tested with OpenJDK 8) uses HANDLES's.\nThe syscalls to lock a file are different and behave different:\n1. _locking uses FD's\n2. LockFileEx + UnlockFileEx uses HANDLE's\n\nLuajLFS will detect which way the JVM uses to implement the RandomAccessFile and will use the appropriate \nsyscall to lock the file depending on the JVM implementation. Due to this, the methods may not behave identical to C\nbased LuaFileSystem depending on how the JVM implemented RandomAccessFile. The main difference is that _locking allows\nthe user to place a lock above a lock already owned by the process replacing the old lock with a new lock. LockFileEx\ndoes not permit this.\n\n#### Operating System differences\nBy default LuajLFS has 3 different modes of operation:\n1. Windows mode Vista and newer (amd64 \u0026 i386)\n2. Linux mode (amd64 \u0026 i386 \u0026 armhf \u0026 aarch64)\n3. Unsupported OS mode\n\nFor more information in regard to which GLIBC version is required for Linux mode see:\nhttps://github.com/AlexanderSchuetz97/JavaNativeUtils\n\nIf for some reason your system does not meet the requirements for Linux or Windows mode LuajLFS will automatically fall back to Unsupported OS mode.\n\nIn Windows and Linux mode LuajLFS should behave nearly identical to C based LuaFileSystem. \n(Some error messages \u0026 codes in some corner cases may be different since I was not able to reproduce them, this holds especially true for Windows)\n\nIn Unsupported OS mode the method lfs.lock file uses the java.nio.FileLock mechanism to lock files rather than OS syscalls.\nAny locks obtained by this mechanism will not be visible by non-Java applications. \nThis means that if you run LuajLFS on for example Mac and want to obtain a lock on a file then \nthis lock will not be \"visible\" to a non-Java application \n(such as for example a C based Lua script locking the same file using C Based LuaFileSystem)\n\nIn Unsupported OS mode the methods lfs.attributes and lfs.symlinkattributes will return only the information which is\navailable by using the JSE Standard operations. Check java.nio.file.attribute.BasicFileAttributes for more info.\nAny other information is set to 0 or an appropriate default value.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderschuetz97%2Fluajlfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderschuetz97%2Fluajlfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderschuetz97%2Fluajlfs/lists"}