Team Spartan Cookies & Milk Forums

Full Version: Starfall Libraries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Make a library system where people can upload code and it can be inducted into a person's code to use. This would be useful if a person wanted, for example, to make a command engine.
this is currently done through shared files, just throw your functions into a table and allow someone else to include/dependency your shared file.
(15-01-2019, 11:23 PM)T-20 Wrote: [ -> ]this is currently done through shared files, just throw your functions into a table and allow someone else to include/dependency your shared file.

How would I include a file?
Also, is there modular support (originally what I'm suggesting)?
I'm not sure I follow on modular support but given it's coded correctly and people include comment files detailing what's in the library for dependency based ones it should feel fairly natural, many people have done it this way previously although I don't think to the amount of modularity that you're thinking of.

check the --@include and --@dependency preprocessors in the SF Documentation for how to add files to your code
So how would I create a module where requiring the file returns a table that does stuff?
requiring a file will allow you access to any non-local variables made within it, so to protect parts of it from manipulation you can use local to restrict access to stuff within the file
Globals are one way to pass around values, but you can also return values from files and they'll be returned by require(). For example:

mymodule/index.txt:
--@name Module Example

local Module = {}

function Module.Hello()
print( "Hello World!" )
end

return Module

In another file:
--@name Include The Module
--@dependency mymodule/index.txt

local Module = require( "mymodule/index" )
Module.Hello()

Includes are recursively resolved in dependencies too, so you can build multi-file libraries in this way.
(17-01-2019, 05:44 PM)Person8880 Wrote: [ -> ]Globals are one way to pass around values, but you can also return values from files and they'll be returned by require(). For example:

mymodule/index.txt:
--@name Module Example

local Module = {}

function Module.Hello()
print( "Hello World!" )
end

return Module

In another file:
--@name Include The Module
--@dependency mymodule/index.txt

local Module = require( "mymodule/index" )
Module.Hello()

Includes are recursively resolved in dependencies too, so you can build multi-file libraries in this way.

I see. Thank you, Person.