This API/Program allows you to compact down projects/APIs into a file format I named ".cmp", this is compacted from a folder "project", the program then lets you import scripts from any of this .cmp files and either run them or initialize them as a new "class" and use their functions! (I kinda stole that bit from bios.lua, I hope no-one minds)
Firstly, there's the program which compacts down your project, this program is extremely simply, you just run it and follow the on-screen commands, but the project format is the most important thing:
Spoiler
Projects don't have a "format" as such, you simply place any folders/files in to one folder then use this folder as you "project directory", the name of the folder without and / is required.The output file cannot have any extension, you just put the name of the .cmp file.
NOTE INHERITANCE:
Spoiler
in scripts which you are compiling you can add a line starting with "inherit" followed by a space and then the import the script is inheriting from, this basically puts all of the code from the import in to where the "inherit" line is when it compiles it.in order to inherit a class inside the project the script is in you must first compile the project then add inherits in, it will not inherit classes from a non existent import.
I added an example inheritance in to the example further down
Updated this by the way, it now doesn't stack overflow and blank lines are ignored,
It also has a cool little percentage timer to show you how far through it is writing your file :D/>/>
(It took about 3-4 seconds to write 738 lines, but it was still a bit annoying not knowing what was happening)
Now there's the more advance bit, the "classy" bit :)/>/>
Spoiler
The classy API has only four functions:
init() - initializes the API, I recommend running this at the beginning and end of your code
import(import) - import is the import directory you are importing (will explain a bit further down)
runClass(class, vars, args) - runs the code as a script (vars and args are optional, look at os.run() to see what they do)
newClass(class) - creates a new instance of the class, returns it as if it were a table
Import explained:
Spoiler
an import is a string, but formatted in a certain way.The import is split by a "." symbol,
the first part is the name of the .cmp file,
the last part is the name of the script
and everything in-between is the folders in the project.
So if I had a script in my "project" folder under "project/billy/general/main" and had compacted "project" to "org" then to import "main" my import would be:
classy.import("org.billy.general.main")
NOTE: imports also have a return table, the table is either nil (import failed) or it contains two values:
{chunk, temp_dir}
chunk is a table containing all the lines of the import, temp_dir is the temporary file of the script, by getting the chunk import can be used to also get the lines of files inside your .cmp file :D/>/>/>
the obvious downside to this is that your scripts/files cannot have an extension, however most scripts on CC don't use extensions anyway so it should be fine :D/>/>
then to run this I would do:
classy.runClass("main")
I can only have one instance of "main" imported at once, this means that I can have as many "mains" in my project as once by every time I wish to use a different one I must import the new one.
Downloads:
Example:
Spoiler
I have a folder called "example", this contains a file called "main" and a folder called "org"In org there's a file called "helloworld" and a folder called "net"
In net there's a file called "test"
So the file tree would look like this:
example
main
org
helloworld
net
test
Main, Helloworld and Test contain these bits of code:
Spoiler
Main:Spoiler
function printTest2(name)
print("PRINTING: "..name)
end
function printTest()
print("Ran loaded API!")
end
Spoiler
local line = "HELLO WORLD"
print(line)
Spoiler
inherit comp.org.helloworld
classy.import("comp.main")
local main = classy.newClass("main")
main.printTest()
main.printTest2("BILLY")
The resulting compile file looks like this:
Spoiler
++comp.main
function printTest2(name)
print("PRINTING: "..name)
end
function printTest()
print("Ran loaded API!")
end
--comp.main
++comp.org.helloworld
local line = "HELLO WORLD"
print(line)
--comp.org.helloworld
++comp.org.net.test
local line = "HELLO WORLD"
print(line)
classy.import("comp.main")
local main = classy.newClass("main")
main.printTest()
main.printTest2("BILLY")
--comp.org.net.test
Now, if we want to run the "test" program and "helloworld" we would do:
classy.init()
classy.import("comp.org.net.test")
classy.import("comp.org.helloworld")
classy.runClass("test")
classy.runClass("helloworld")
classy.init()
And that would be it, running those classes would output:
Hello world
Ran loaded API
PRINTING: BILLY
Hello world
NOTE:
this uses a folder in your computer called "temp", any files in temp will get deleted after you init(), this is because these files are temporary, for use by both runClass() and newClass()
Thanks!