Jump to content


Janne's Content

There have been 4 items by Janne (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#277505 [N00b] - Trouble using IO library

Posted by Janne on 02 June 2018 - 03:50 PM in Ask a Pro

View PostZepate, on 01 June 2018 - 02:36 PM, said:

  • there is no tutorial on how to write files from lua in CC
  • the IO api is not enought documented
  • the use of fs api provide missleading coding style with IO api (note the notation "." and ":" for the same purpose)
The IO api is just not documented on the wiki, but the wiki does link to the official lua documentation for the IO library http://www.lua.org/m...manual.html#5.7

View PostZepate, on 01 June 2018 - 02:36 PM, said:

  • the hard way but more flexible way is to use IO library
  • the quick and dirty yet powerfull way is to use FS library (CC endemic not sure if it is CraftOS endemic)
The IO library is just a wrapper around the fs library, I don't quite see how the IO library is "harder" and\or more "flexible" when it has less features than fs.



#277504 reqpack: Package all your requirements into a single file without any installers

Posted by Janne on 02 June 2018 - 03:32 PM in APIs and Utilities

So, I just tested this and noticed that you replace every require call with a custom one(__require__). Earlier I've been using lua squish(does not work well on windows) which extracts the code from each files and puts it in the package.preload table, leaving the require calls as is. Really neat what you've done, but personally I'd prefer it if package.preload was used.



#277497 libloader: Lua require support (5.3)

Posted by Janne on 01 June 2018 - 12:49 PM in APIs and Utilities

Not quite sure I understand, does 1.8 support require? If it does that is great!



#277485 libloader: Lua require support (5.3)

Posted by Janne on 31 May 2018 - 11:50 PM in APIs and Utilities

libloader

Decided to write a small library that adds support for lua require. I see now after writing this utility that it has been done before by Oddstr13 thought this one is a bit different. Instead of being based on 5.1 docs I based it on 5.3 docs, the only difference afaik being that 5.3 renamed package.loaders to package.searchers.

One thing this library supports which Oddstr13 didn't is the possibility of loading libraries from the program's working directory by using "./" in the package.path string

Basic usage
local _libloader = dofile("path/to/libloader")
local mylibrary = require("mylibrary")

mylibrary.doSomething()
By default libloader is set up to look for libraries in the program's working directory (including <workdir>/lib and <workdir>/bin)
if it doesn't find anything there it will look in /lib and /bin
By default it will not find non lua files when looking in <workdir> due to the possibility of accidentally loading
a non library like a config file.

package.path is set to "./?.lua;./lib/?.lua;./lib/?;./bin/?.lua;./bin/?;/lib/?.lua;/lib/?;/bin/?.lua;/bin/?"
but it can be changed by calling setPath
local _libloader = dofile("path/to/libloader")

_libloader.setPath("./?.lua")

local mylibrary = require("mylibrary")

mylibrary.doSomething()


Lua 5.3 doc: http://www.lua.org/m...al.html#Modules
Pastebin: https://pastebin.com/tt8eQALP

Moonscript source:
Spoiler

Transpiled lua:
Spoiler