Team Spartan Cookies & Milk Forums
Starfall Libraries - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Feedback (https://teamscm.co.uk/forum-9.html)
+--- Forum: Suggestions and improvements (https://teamscm.co.uk/forum-11.html)
+--- Thread: Starfall Libraries (/thread-2932.html)



Starfall Libraries - exoRift - 15-01-2019

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.


RE: Starfall Libraries - TheOneAndOnlyTee - 15-01-2019

this is currently done through shared files, just throw your functions into a table and allow someone else to include/dependency your shared file.


RE: Starfall Libraries - exoRift - 15-01-2019

(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)?


RE: Starfall Libraries - TheOneAndOnlyTee - 16-01-2019

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


RE: Starfall Libraries - exoRift - 17-01-2019

So how would I create a module where requiring the file returns a table that does stuff?


RE: Starfall Libraries - TheOneAndOnlyTee - 17-01-2019

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


RE: Starfall Libraries - Person8880 - 17-01-2019

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.


RE: Starfall Libraries - exoRift - 17-01-2019

(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.