-
Notifications
You must be signed in to change notification settings - Fork 1
melon
melon
Main module table for the library
melon.thirdparty - melon.noise - melon.PanelDevSuite - melon.masks - melon.http - melon.net - melon.tool - melon.panels - melon.iter - melon.colors - melon.math - melon.text - melon.table - melon.lua - melon.char - melon.stencil - melon.str - melon.sql - melon.elements - melon.string

melon.AF(table: table, name: string, default: any)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | table | table | Table to add the accessor to |
| 2 | name | string | String name for the accessor |
| 3 | default | any | Default value for the accessor |
Good replacement for AccessorFunc

melon.AccessorFunc(table: table, name: string, default: any, type: TYPE_)

melon.AddDynamicLogHandler(log: func(log: table)) -> number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | log | func(log: table) | Function to call when logging, called with logdata |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | type | number | Log Level |
Adds a log handler which just appends to the previous logtypes, returns the level of this handler
Adds a load handler for melonlib, sh_, cl_ and sv_ are all loadhandlers

melon.AddLogHandler(level: number, log: func(level: table))
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | level | number | Number, log level |
| 2 | log | func(level: table) | Function to call when logging, called with logdata |
Adds a log handler

melon.Advise(text: string, length: number, color: Color, font: string, x: number, y: number, xmul: number, ymul: number, dist: number) -> number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | text | string | The text to display |
| 2 | length | number | The length it should live |
| 3 | color | Color | The color of the text |
| 4 | font | string | The font of the text |
| 5 | x | number | Where to place it, X |
| 6 | y | number | Where to place it, Y |
| 7 | xmul | number | How far it should move horizontally every tick, relative to how much it wants to |
| 8 | ymul | number | How far it should move vertically every tick, relative to how much it wants to |
| 9 | dist | number | How far it should move total |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | number | The ID of the advice created |
Quickly creates a new "advisory", quick UI feedback

melon.AdviseX(advise: melon.ADVISEINFO) -> number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | advise | melon.ADVISEINFO | The advisory info |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | number | The ID of the advisory created |
Creates a new "advisory", quick UI feedback

melon.Assert(expr?: bool, fmt: string, any...) -> bool?
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | expr? | bool | Did this expression pass Must be true to pass |
| 2 | fmt | string | Format string error if we failed |
| 3 | any | any... | Arguments to pass to the formatter |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | bool | bool | Did assertion fail |
Asserts that the expression is explicitly true, truey is not accepted.

melon.AssertEq(lhs: any, rhs: any, fmt?: string, any...) -> bool?
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | lhs | any | Left hand side value to compare |
| 2 | rhs | any | Right hand side value to compare |
| 3 | fmt? | string | Format string error if we failed |
| 4 | any | any... | Additional arguments to pass to the formatter |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | bool | bool | Did the assertion fail |

melon.DeQuickSerialize(str: string) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | str | string | String to deserialize |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tbl | table | Deserialized table |
Deserialized a table serialized with melon.QuickSerialize

melon.Debug(f: func, clr?: bool, args: any...) -> bool?
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | f | func | Function to call on hot refresh |
| 2 | clr? | bool | Clear the console before executing |
| 3 | args | any... | Arguments to pass to the given function |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | did | bool | Are debug functions allowed to be ran |
Executes a function only after the gamemodes loaded, used for hot refreshing and stuff

melon.DebugHook(enabled?: bool, hook: string, fn: function)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | enabled? | bool | Is this enabled |
| 2 | hook | string | Hook to hook onto |
| 3 | fn | function | Function to set the hook to |
Sets a debug hook

melon.DebugID(id: string)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | string | The string to make unique |

melon.DebugKeybind(key: KEY_, fn: function)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | key | KEY_ | KEY_ enum to hook |
| 2 | fn | function | Function to call on press |
Adds a debug keybind, this is overriden on file save so you can only have one

melon.DebugNamed(name: string, fn: func, va: any...)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Name of the debug test |
| 2 | fn | func | Function to call |
| 3 | va | any... | Arguments to pass |
Registers or calls (if no fn is provided) a "named debug" test, for convenient reuse

melon.DebugNewFileDetected(f: string)

melon.DebugOnce(f: func, clr?: bool, args: any...) -> bool?
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | f | func | Function to call on hot refresh |
| 2 | clr? | bool | Clear the console before executing |
| 3 | args | any... | Arguments to pass to the given function |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | did | bool | Are debug functions allowed to be ran |
Identical to melon.Debug except its on a slight delay to stop double refreshing

melon.DebugPanel(name: string, fun: func)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Panel name registered with [vgui.Register] |
| 2 | fun | func | Function thats called with the panel as its only argument |
Creates a debug panel containing the given function, lay this out in fun()

melon.DebugPanel2(name: string, fun: func)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Panel name registered with [vgui.Register] |
| 2 | fun | func | Function thats called with the panel as its only argument |
Creates a debug panel containing the given function, lay this out in fun(), visual and functional improvement of melon.DebugPanel

melon.DebugPlayer(bots: bool) -> Player
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | bots | bool | If true, include bots in the search |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | player | Player | The first player on the server thats superadmin |
Gets a player for debug use

melon.DebugRun(id: string, name: string, args: any...) -> any...
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | string | Hook to run |
| 2 | name | string | Hook name to run |
| 3 | args | any... | Any values to give to the hook |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | ret | any... | Any return values |
Runs a Hook debug

melon.DebugSlider(fn: function, speed: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | fn | function | Function to call when the slider changes |
| 2 | speed | number | Play speed, defaults to 2 |
Creates a slider panel to debug animations

melon.DebugWrap(fn: func) -> func
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | fn | func | Function to wrap Debug around |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | fn | func | Wrapped function |
Wraps a function in Debug, equal to doing:
local x = function(...) melon.Debug(f, _, ...) end

melon.DrawAvatar(stid: string, x: number, y: number, w: number, h: number) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | stid | string | SteamID64 of the player to draw the avatar of |
| 2 | x | number | X of the image to draw |
| 3 | y | number | Y of the image to draw |
| 4 | w | number | W of the image to draw |
| 5 | h | number | H of the image to draw |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | drawn | bool | If the image has been drawn or not, false if loading, true if drawn |
Draws a players avatar image reliably.

melon.DrawBlur(panel: panel, localX: number, localY: number, w: number, h: number, passes: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | panel | panel | Panel to draw the blur on |
| 2 | localX | number | X relative to 0 of the panel |
| 3 | localY | number | Y relative to 0 of the panel |
| 4 | w | number | W of the blur |
| 5 | h | number | H of the blur |
| 6 | passes | number | How many passes to run, basically the strength of the blur |
Draws blur!

melon.DrawImage(url: string, x: number, y: number, w: number, h: number) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | URL to the image you want to draw |
| 2 | x | number | X of the image to draw |
| 3 | y | number | Y of the image to draw |
| 4 | w | number | W of the image to draw |
| 5 | h | number | H of the image to draw |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | drawn | bool | If the image has been drawn or not, false if loading, true if drawn |
Draw an image, handles loading and everything else for you, for use in a 2d rendering hook.

melon.DrawImageRotated(url: string, x: number, y: number, w: number, h: number, rot: number) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | URL to the image you want to draw |
| 2 | x | number | X of the image to draw |
| 3 | y | number | Y of the image to draw |
| 4 | w | number | W of the image to draw |
| 5 | h | number | H of the image to draw |
| 6 | rot | number | Rotation of the image to draw |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | drawn | bool | If the image has been drawn or not, false if loading, true if drawn |
Identical to melon.DrawImage except draws it rotated

melon.DrawPanelBlur(panel: panel, passes: type)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | panel | panel | Panel to draw the blur on |
| 2 | passes | type | How many passes to run, basically the strength of the blur |
Draws blur based on a given panels dimensions

melon.Find(iter: func, t: table, fn: func) -> any
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iter | func | The iterator function to use. |
| 2 | t | table | The table to search in. |
| 3 | fn | func | The reducer function. The function is passed the value, the key, and returns a boolean. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | any | The found value, or nil. |
Loops through t using iter and tests each element with fn. The first to return true

melon.Font(size: number, font: string, weight: number) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Font size to be scaled |
| 2 | font | string | Optional, font to base the new font off of |
| 3 | weight | number | Optional, font weight |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Font identifier |
For use in 2d rendering hooks, create a font if it doesnt exist with the given size/fontname.

melon.FontGenerator(font: string) -> melon.FontGeneratorObject
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | font | string | Font name for the generator to use |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | gen | melon.FontGeneratorObject | [melon.FontGeneratorObject] that has the given font |

melon.GenerateSuperellipse(n: number, x: number, y: number, w: number, h: number, resolution: number) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | n | number | The number that defines the shape of the superellipse |
| 2 | x | number | X coordinate of the superellipse |
| 3 | y | number | Y coordinate of the superellipse |
| 4 | w | number | Width of the superellipse |
| 5 | h | number | Height of the superellipse |
| 6 | resolution | number | Resolution of the superellipse, defaults to 4, lower the number, higher the quality |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | poly | table | Polygon table, for use with [surface.DrawPoly] |
Generates a superellipse or "squircle" polygon, see https://en.wikipedia.org/wiki/Superellipse

melon.GenerateSuperellipseMesh(n: number, x: number, y: number, w: number, h: number, resolution: number) -> IMesh
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | n | number | The number that defines the shape of the superellipse |
| 2 | x | number | X coordinate of the superellipse |
| 3 | y | number | Y coordinate of the superellipse |
| 4 | w | number | Width of the superellipse |
| 5 | h | number | Height of the superellipse |
| 6 | resolution | number | Resolution of the superellipse, defaults to 5, lower the number, higher the quality |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | mesh | IMesh | Mesh of the given superellipse |
Identical to melon.GenerateSuperellipse except this generates a Mesh instead of a Polygon

melon.GetPlayerAvatar(stid64: string) -> IMaterial
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | stid64 | string | SteamID64 of the players avatar youd like to get |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | avatar | IMaterial | Material of the players avatar, unreliable, will return nil if invalid |
Gets a players avatar image from the cache if it exists and initiates downloading it if not, dont use.

melon.GradientBuilder(id: any, colors: table) -> melon.GradientBuilderObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | any | The identifier for the builder |
| 2 | colors | table | A sequential table of {step:number, color:Color}, optional |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | builder | melon.GradientBuilderObj | The gradient builder object |
local g = melon.GradientBuilder("some_identifier")
:Step(0, Color(255, 0, 0))
:Step(25, Color(255, 0, 255))
:Step(75, Color(0, 255, 0))
:Step(100, Color(0, 0, 255))
hook.Add("HUDPaint", "RenderGradient", function()
g:Render(10, 10, 150, 150)
end )

melon.Grid(w: number, h: number) -> melon.GridObject
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | w | number | Width to create the grid as |
| 2 | h | number | Height to create the grid as |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | grid | melon.GridObject | Grid object that was created |
Creates a melon.GridObject

melon.GroupBy(iter: func, t: table, fn: func) -> any
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iter | func | The iterator function to use. |
| 2 | t | table | The table to group. |
| 3 | fn | func | The reducer function. The function is passed the value, the key, and returns a boolean. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | any | A table of tables, containing the groups. |

melon.HTTP(data: HTTPRequest)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | data | HTTPRequest | Data to execute with |
Queues an HTTP request to run whenever available

melon.Image(url: string, callback: func)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | URL to the image to download |
| 2 | callback | func | Function to be called when download finished/image retrieved, called with IMaterial |
Remote image downloader and cache handler. Discord is unreliable, use imgur.

melon.IsPromise(obj: any) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | obj | any | The object to test |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | ispromise | bool | Is this object a [melon.PromiseObj] |
Is the given object a promise?

melon.IsPromiseError(obj: any) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | obj | any | Object ot test |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iserr | bool | Is this object a [melon.PromiseErrorObj] |
Tests if an object is a promise error

melon.JMap(iter: func, t: table, fn: func) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iter | func | The iterator function to use. |
| 2 | t | table | The table to map. |
| 3 | fn | func | The mapping function. The function is passed the value then the key, and is expected to return a new value. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | table | A table with the mapped elements. |

melon.Join(iter: func, t: table, sep: string) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iter | func | The iterator function to use. |
| 2 | t | table | The table to join. |
| 3 | sep | string | The reducer function. The function is passed the value, the key, and returns a boolean. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | string | The joined value. |
Loops through t using iter and concats each element into a string separated by sep.

melon.KV2VK(tbl: table) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tbl | table | Table to convert |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | table | Converted table |
Inverts a tables keys and values (invalidlink(k) = v) into (invalidlink(v) = k) for every pair in the given table.

melon.KillAdvise(id: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | number | The advisory ID to kill |
Removes the given advisory immediately

melon.LoadModule(folder: string)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | folder | string | Module folder name to load |
Loads a module from modules/ dynamically, reading init and everything else.

melon.Log(level: number, fmt: string, fmtargs: any...)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | level | number | The log level |
| 2 | fmt | string | String format to log |
| 3 | fmtargs | any... | Arguments for the formatter |
Formats and logs a message, also calls the hook Melon:Log with the logdata

melon.MODULE(name: string) -> melon.MODULEOBJ
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Module to get the object of |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | mod | melon.MODULEOBJ | Module object of the name |
Get the melon.MODULEOBJ of the given name if it exists.

melon.Map(tbl: table, fn: func) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tbl | table | Table to map |
| 2 | fn | func | Function that takes k,v and returns a new k,v |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | table | Table created by the mapper |
Maps a table to a new table, calling func with every key and value.

melon.Material(path: string, opts: string) -> IMaterial
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | path | string | Path to the image |
| 2 | opts | string | Optional, Options to give the material, identical to [Material]'s second arg |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | IMaterial | Material to the path given |
Automatically caches and returns materials, helper function for rendering hooks, identical to invalidlink(Material) except cached

melon.NewStream() -> melon.STREAM
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | stream | melon.STREAM | The new stream |
Creates a new melon.STREAM object, initialized without any data

melon.Pack(args: any...) -> number, table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | args | any... | The varargs to pack. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | length | number | The length of the varargs. |
| 2 | args | table | A table containing the passed varargs. |
Takes a variable length of arguments and packs them into a table while also returning the length.

melon.ParseCommandArgs(string, flags?: table<string, number>) -> table<string>, table<string, table<string>>

melon.ParseURL(url: string) -> melon.URL
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | The URL to parse |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | melon.URL | The parsed URL object |

melon.ParseVersion(text: string) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | text | string | A string of 3 parts separated by . |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | vers | table | Table that contains 3 members, major, minor and patch |
Parses a string in the format major.minor.patch, 1.0.0, 45.56.67 into the version itself

melon.PostLoad(fn: func)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | fn | func | Function to call post load |
Call a function post load, needed because of load order issues

melon.Promise(executor: fn) -> melon.PromiseObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | executor | fn | The promise executor function |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | promise | melon.PromiseObj | The created promise |
Creates a promise

melon.PromiseError(options: table) -> melon.PromiseErrorObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | options | table | Object ot test |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | obj | melon.PromiseErrorObj | The promise error |
Creates a melon.PromiseErrorObj

melon.PromiseWithTraceback(traceback: string, executor: fn, parent?: melon.PromiseObj) -> melon.PromiseObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | traceback | string | Traceback that this promise is at |
| 2 | executor | fn | The promise executor function |
| 3 | parent? | melon.PromiseObj | The parent promise |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | promise | melon.PromiseObj | The created promise |
Creates a promise with a user defined traceback
Serializes a table very simply, only allows string keys and values format is key::'value;key2::'value2;

melon.Reduce(iter: func, t: table, fn: func, initial_value: any) -> any
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | iter | func | The iterator function to use. |
| 2 | t | table | The table to reduce. |
| 3 | fn | func | The reducer function. The function is passed the current value, the value, the key, and returns the next value. |
| 4 | initial_value | any | The initial value passed to fn. |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | any | The reduced value. |
Performs a reduction on the given iter with the given fn.

melon.ResolvedPromise() -> melon.PromiseObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | promise | melon.PromiseObj | The resolved promise |
Creates a resolved promise

melon.RunAllPromises(promises: table)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | promises | table | The table of promises |
Runs a table of melon.PromiseObjes

melon.SanitizeURL(url: string) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | URL to sanitize |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | new | string | Sanitized URL |
Sanitize a URL for use in filenames, literally only allows alpha characters

melon.Scale(numin: number) -> number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | numin | number | Number to scale |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | numout | number | Scaled number |
Scales a number based on invalidlink(ScrH) / 1080

melon.ScaleBy(by: number) -> func(by: number) -> number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | by | number | Number to scale by |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | func | func(by: number) -> number | Function that scales by the given factor |
Creates a function to scale a number by

melon.ScaleN(numin: number...) -> number...
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | numin | number... | Vararg numbers to scale |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | numout | number... | Unpacked scaled numbers |
Scales multiple numbers

melon.SpecialFont(size: number, FontData) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Font size |
| 2 | FontData | FontData | Options to give the font |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Font identifier |

melon.StackOverflowProtection(id: any) -> bool?
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | id | any | Identifier used for tracking |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | run | bool | Should the loop stop |
Tracks a loop with the given id to prevent stack overflows, nothing fancy.

melon.SubTable(tbl: table, from: number, to: number) -> table
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tbl | table | Table to get the subtable of |
| 2 | from | number | Starting index |
| 3 | to | number | Ending index |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | sub | table | Subtable of the given arguments |
Gets a subtable of the given table from the range of from to to, think string.sub()

melon.TestGradient() -> melon.GradientBuilderObj
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | builder | melon.GradientBuilderObj | The test gradient |
Creates a standardized test gradient

melon.TextGradient(text: string, font: string, x: number, y: number, colors: table, local_to: Panel, rotation: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | text | string | The text to render |
| 2 | font | string | The font of the text |
| 3 | x | number | The X coord to render it at |
| 4 | y | number | The Y coord to render it at |
| 5 | colors | table | A sequential table of {step:number, color:Color} |
| 6 | local_to | Panel | Position this gradient local to this panel, will also clip to it |
| 7 | rotation | number | Rotation of the gradient, optional |
Renders a piece of gradient text
local c = {
{0, Color(84, 158, 200)},
{35, Color(101, 58, 192)},
{70, Color(143, 0, 255)},
{90, Color(152, 43, 138)},
{100, Color(156, 62, 84)},
}
hook.Add("HUDPaint", "TextGradientRender", function()
melon.TextGradient("Some Text", melon.Font(30), 10, 10, c)
end )

melon.URLExtension(url: string) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | url | string | URL to get the file extension of |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | ext | string | Extension of the URL given |
Gets the extension of a url, relic of the ancient past, dont use.

melon.UnscaledFont(size: number, font: string) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Font size raw |
| 2 | font | string | Optional, font to base the new font off of |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | name | string | Font identifier |
Same as melon.Font except the size is unscale.
Takes a variable length of arguments and packs them into a table while also returning the length. This function also forwards an initial `success` value separately of the rest of the varargs.
If you dont understand the source for this, dont use it.
"Clears" the console by spamming newlines, only functions post gamemode loaded
Font Generator Object

melon.FontGeneratorObject:Unscaled(size: number, weight: number) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Font size |
| 2 | weight | number | Font weight |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | font | string | Font identifier |
Identical to melon.FontGeneratorObject:Font except unscaled

melon.FontGeneratorObject:Preprocess(size: number, font: string, weight: number) -> number, number, string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Size of the wanted font |
| 2 | font | string | Font of the wanted font |
| 3 | weight | number | Weight of the wanted font |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | New size of the wanted font |
| 2 | weight | number | New font of the wanted font |
| 3 | font | string | New weight of the wanted font |

melon.FontGeneratorObject:Font(size: number, weight: number) -> string
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | size | number | Font size to be scaled |
| 2 | weight | number | Font weight |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | font | string | Font identifier |
Creates a new font with the given size and font from the object

melon.GradientBuilderObj:Render(x: number, y: number, w: number, h: number, ign?: bool)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | x | number | X coordinate to render this gradient at |
| 2 | y | number | Y coordinate to render this gradient at |
| 3 | w | number | Width of the gradient |
| 4 | h | number | Height of the gradient |
| 5 | ign? | bool | Ignore the offset of [melon.GradientBuilderObj:LocalTo] |
Renders the gradient to the screen at the given position

melon.GradientBuilderObj:Reset() -> self
Resets all steps, if you dont do this and you add steps every frame you will cause a crash

melon.GradientBuilderObj:ColorMod(tl: Color, tr: Color, bl: Color, br: Color) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tl | Color | Top left color |
| 2 | tr | Color | Top right color |
| 3 | bl | Color | Bottom left color |
| 4 | br | Color | Bottom right color |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The gradbuilder |
Modifies the color of a certain quadrant of the gradient

melon.GradientBuilderObj:Alpha(tl: number, tr: number, bl: number, br: number) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | tl | number | Top left alpha |
| 2 | tr | number | Top right alpha |
| 3 | bl | number | Bottom left alpha |
| 4 | br | number | Bottom right alpha |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The gradbuilder |

melon.GradientBuilderObj:LocalTo(panel: Panel) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | panel | Panel | The panel that this gradient is local to |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The gradbuilder |

melon.GradientBuilderObj:Build(x: number, y: number, w: number, h: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | x | number | X coordinate to build the mesh to |
| 2 | y | number | Y coordinate to build the mesh to |
| 3 | w | number | Width of the gradient |
| 4 | h | number | Height of the gradient |

melon.GradientBuilderObj:Invalidate()
Invalidates the current mesh, causing it to rebuild

melon.GradientBuilderObj:Material() -> IMaterial
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | mat | IMaterial | The material of the gradient |
Renders the gradient to a material and returns it

melon.GradientBuilderObj:Step(perc: number, color: Color) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | perc | number | The % of where this step is |
| 2 | color | Color | The color of this step |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The gradbuilder |
Adds a step to the gradient with the given %
melon.GradientBuilder()
:Step(0, red) --- 0%
:Step(50, green) --- 50%
:Step(100, blue) --- 100%

melon.GradientBuilderObj:Vertical(vertical: bool) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | vertical | bool | Vertical (true) or horizontal (false) |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The gradbuilder |
Should this gradient be top to bottom instead of left to right?

melon.GradientBuilderObj:ToCSS() -> string
Generates a linear-gradient() CSS function call that correlates to this gradient ingame
Grid Object Class

melon.GridObject:Increment(x: number, y: number)
Increments the value at the given coord

melon.GridObject:GetSize() -> number, number
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | w | number | Width of the object |
| 2 | h | number | Height of the object |
Get the size of the grid

melon.GridObject:Set(x: number, y: number, val: any)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | x | number | X to set |
| 2 | y | number | Y to set |
| 3 | val | any | Value to set the coord to |
Sets a value at X and Y to the given value

melon.GridObject:SetSize(w: number, h: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | w | number | Width to set |
| 2 | h | number | Height to set |
Set the size of the grid
Updates the grid object

melon.GridObject:Get(x: number, y: number) -> any
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | x | number | X to get |
| 2 | y | number | Y to get |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | val | any | Value of the coord |
Gets a value at the given coords
Defines a melonlib module
All of these values have Set*/Get* methods for them. They can also be indexed by their name, object.*
| Name | Type | Comment |
|---|---|---|
| Name | string | Name of the module |
| ID | string | Folder of the module |
A promise object

melon.PromiseObj:Next(success: fn, failure: fn) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | success | fn | Function to call on success |
| 2 | failure | fn | Function to call on failure |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self | The PromiseObj |
Attaches a success/and or failure handler.
Marks the Promise as cancelled, and cancels all consuming Promises.
Simple way to pass around a mutable string builder

melon.STREAM:WriteLn(data: string) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | data | string | The string to write to the buffer |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self |
Appends a string to the end of the buffer, identical to melon.STREAM:Write except it also appends a newline.

melon.STREAM:Write(data: string) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | data | string | The string to write to the buffer |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self |

melon.STREAM:Append(stream: melon.STREAM) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | stream | melon.STREAM | The stream to append, gets consumed |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self |
Appends the given stream to the current stream

melon.STREAM:Consume()() -> string
Gets the written string and resets the stream,

melon.STREAM:WriteFmt(fmt: string, any...) -> self
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | fmt | string | String format to use, see [melon.string] for a reference |
| 2 | any | any... | Any values to be passed to the formatter |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | self | self |
Appends a melon.string.Format formatted string to the end of the buffer
A URL represented by its component parts
All of these values have Set*/Get* methods for them. They can also be indexed by their name, object.*
| Name | Type | Comment |
|---|---|---|
| name | type | Description |
Note
DataClasses act as regular classes, except that they are virtual constructs used only one place, usually passing to or from functions.

Information for advisories
All values are optional, (see melon.AdviseX)
| Name | Type | Comment |
|---|---|---|
| time | number | Time to start at, CurTime
|
| text | string | Text to display |
| length | number | Time in seconds to run |
| dist | number | How far to move total |
| pos | table<number> | Table (x, y) to unpack into the position |
| x | number | X coordinate to display at |
| y | number | Y coordinate to display at |
| xmul | number | How far to move horizontally every frame |
| ymul | number | How far to move vertically every frame |
| sinmul | number | How strong should a sine wave for movement be |
| xsin | number | How strong should the sine wave be horizontally |
| ysin | number | How strong should the sine wave be vertically |
| font | string | Font name of the text |
| color | Color | Color of the text |
Information passed to and from the logger
| Name | Type | Comment |
|---|---|---|
| message | string | Message passed to the logger, post format |
| trace | string | Traceback from the caller |
| time | number | Time from os.time from when the log was created |
| level | melon.LOG_ | Logging level |
| handler | fn | The handler function |
| fmt_time | string | The formatted time of when the logging took place |
Log types
| Name | Description |
|---|---|
| LOG_IMPORTANT | Important, green text |
| LOG_ERROR | Error, red text or an actual error on the client |
| LOG_WARNING | A warning |
| LOG_MESSAGE | A verbose message |

Melon:Debug(time: number)
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | time | number | When the hook was ran, from os.time. |
Called when melon.Debug is called and should run
Called after MelonLib is done loading entirely
-- For using melonlib utilities from outside a module
local function load()
AddCSLuaFile("some_cl_file.lua")
if CLIENT then
include("some_cl_file.lua")
end
end
hook.Add("Melon:DoneLoading", load)
if melon then
load()
end Called after the core is loaded but before any modules are loaded

Melon:NetSchema:Recv(data: table, ply: Player) -> bool
Argument and Return information
| # | Name | Type | Description |
|---|---|---|---|
| 1 | data | table | The data sent over the net message |
| 2 | ply | Player | If SERVER, then the player that sent it, otherwise nil |
| # | Name | Type | Description |
|---|---|---|---|
| 1 | skip | bool | If true, skip calling recv on the schema object |
Called when a NetSchema message is sent
