ArkScript
A small, fast, functional and scripting language for video games
|
Important note related to the routes: in case the given content argument doesn't return the wanted values, it will silently fail to avoid crashing the server.
Create the server (only one per VM may be instanciated).
Parameters
Return value nil
Author
Example
Create a route to answer the specified request type.
Parameters
route
: a string representing the route to handle. The route can receive matches with the regex syntax, eg /(\\d+)
to match on numbershandler
: a function returning a list [status-code content type]
status-code
: number, representing an HTTP codecontent
: stringtype
: string, the mimetype for content
The typical handler
function looks like this: (fun (matches body params) ...)
:
matches
is a list of matches (as strings). If none were found, it will be nil
body
is a string, the request's body ; for GET requests this is always nil
params
is a UserType<http:Params>
sent to the function if any, otherwise nil
Return value nil
Author
Example
Stop a server.
Parameters
Return value nil
Author
Example
Setup the server to listen forever. Should only be called once after having setup all the routes.
Parameters
host
: a string ; an IP address or localhost
port
: a number, optional if the host is 0.0.0.0
(= bind to all interfaces)Return value nil
Author
Example
Mount a given directory to a specific location. You can mount a directory to multiple locations, thus creating a search order.
Parameters
mountpoint
: string, a routeport
: string, a folder on the computerReturn value bool
, true if it worked, false if the base directory doesn't exist.
Author
Example
Remove a mount point.
Parameters
mountpoint
: string, a mountpoint nameReturn value bool
, false if the mount point can't be found, true otherwise.
Author
Example
Map a file extension to a mimetype.
Return value nil
Parameters
extension
: string, a file extensionmimetype
: string, a mimetypeBuilt-in mappings:
Extension | MIME Type |
---|---|
txt | text/plain |
html, htm | text/html |
css | text/css |
jpeg, jpg | image/jpg |
png | image/png |
gif | image/gif |
svg | image/svg+xml |
ico | image/x-icon |
json | application/json |
application/pdf | |
js | application/javascript |
wasm | application/wasm |
xml | application/xml |
xhtml | application/xhtml+xml |
Author
Example
Set the logging level, by default 0.
Parameters
loglevel
: numberLogger level 1 will display the timestamp, request method, path and response status.
Level 2 will add the request body as well.
Return value nil
Author
Example