CC: Tweaked

CC: Tweaked

42M Downloads

Dedicated storage for library code

djmattyg007 opened this issue ยท 9 comments

commented

I've written a bunch of common "library" code that I'd like to share between computers. Is there an easy way to do this? Right now I have to manually copy it between computers, and then I have to manually keep it up to date too.

commented

Even if there was no way to share it between computers, it would still be ideal if there was a dedicated path within each computer for storing this code that was automatically added to package.path. Right now I store it in the root folder of each computer, and add this to the top of every script:

package.path = "/?;/?.lua;/?/init.lua;" .. package.path
commented

If you are playing singleplayer then you could create a custom datapack.

commented

Would you be able to expand on that? How does it work? How would I learn to do that? What makes that solution exclusive to single player?

commented

https://github.com/cc-tweaked/datapack-example. The readme explains pretty much all of the how-to. It's not exclusive to single player per se, it's just that you need admin access to the multiplayer server in order to make it load a pack, which isn't always an option. Also the datapack content will affect all computers, which may not always be a great idea in multiplayer.

commented

In-game solution could be to store this library on a disk, and connect every computer to the same disk drive (wired network). Put a startup on the disk which load the library. Then you can use this library on every computers, from a single file.

commented

I don't mind the datapack idea too much, but it isn't very dynamic. Every change would require reloading configuration in full.

commented

Who needs storage?! ๐Ÿ˜„

Alternative approach: If HTTP is allowed, you could make use of http.get+load+pcall Lua functions to dynamically run Lua code from pastebin or GitHub repo/gist or whatever ๐Ÿ˜‰
This has several benefits, as you can just update the file remotely by using git (in case you're using github repo/gist), or just use web UI in case you're not familiar with git.


Here goes a live example:

  1. Download/copy/save the runlib script to your CC computer, you can also use wget command.
  2. Open terminal and enter runlib Cheatoid:printf, this would download and import the library into Lua environment.
  3. Now you can call a brand new printf function in your Lua scripts. You can also use runlib("libraryId") from within Lua.
  4. By utilizing startup script, you can take this further. It is also possible to make a system which automatically updates libraries on all target computers, etc.

image

commented

That is deliciously horrifying ๐Ÿ˜…

commented

i wish that package.path would be something you can edit globally and have it work globally
that or a read/writable folder that you can put libraries in that is automatically on package.path