Skip to content
garryspins edited this page Feb 27, 2026 · 9 revisions

melon


shared link

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

Members

melon.InvalidImage

shared link

Material for loading images

melon.LogTypes

shared link

List of all log types

melon.Modules

shared link

Table of all melon.MODULEOBJ's loaded

melon.version

shared link

Version in major.minor.patch format, see melon.ParseVersion

Functions

melon.AF

shared link
melon.AF(table: table, name: string, default: any)

Argument and Return information

Arguments

# 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.AT

shared link

[!NOTE]
This is an alias of melon.AccessorTable

melon.AccessorFunc

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

Argument and Return information

Arguments

# Name Type Description
1 table table Table to add the accessor to
2 name string String name of the key
3 default any Default value of the accessor key
4 type TYPE_ Type of the accessor
Adds an accessor function to the given table and sets the default if needed Differences between AccessorFunc - `tbl:Set*()` calls `tbl:OnAccessorChange(name, from, to)` if it exists on the given table - `tbl:Set*()` returns `tbl` - Restricts to a TYPE_ enum instead of a FORCE_

melon.AccessorTable

shared link
melon.AccessorTable()

Dont use this

melon.AddDynamicLogHandler

shared link
melon.AddDynamicLogHandler(log: func(log: table)) -> number

Argument and Return information

Arguments

# Name Type Description
1 log func(log: table) Function to call when logging, called with logdata

Returns

# 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

melon.AddLoadHandler

shared link internal
melon.AddLoadHandler()

Adds a load handler for melonlib, sh_, cl_ and sv_ are all loadhandlers

melon.AddLogHandler

shared link
melon.AddLogHandler(level: number, log: func(level: table))

Argument and Return information

Arguments

# 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

shared link
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

Arguments

# 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

Returns

# Name Type Description
1 id number The ID of the advice created

Quickly creates a new "advisory", quick UI feedback

melon.AdviseX

shared link
melon.AdviseX(advise: melon.ADVISEINFO) -> number

Argument and Return information

Arguments

# Name Type Description
1 advise melon.ADVISEINFO The advisory info

Returns

# Name Type Description
1 id number The ID of the advisory created

Creates a new "advisory", quick UI feedback

melon.Assert

shared link
melon.Assert(expr?: bool, fmt: string, any...) -> bool?

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 bool bool Did assertion fail

Asserts that the expression is explicitly true, truey is not accepted.

melon.AssertEq

shared link
melon.AssertEq(lhs: any, rhs: any, fmt?: string, any...) -> bool?

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 bool bool Did the assertion fail
Asserts that `lhs == rhs`, otherwise we melon.Log an error Note that the first two arguments to the formatter are `lhs` and `rhs`

melon.CheckForUpdates

shared link internal
melon.CheckForUpdates()

melon.DeQuickSerialize

shared link
melon.DeQuickSerialize(str: string) -> table

Argument and Return information

Arguments

# Name Type Description
1 str string String to deserialize

Returns

# Name Type Description
1 tbl table Deserialized table

Deserialized a table serialized with melon.QuickSerialize

melon.Debug

shared link
melon.Debug(f: func, clr?: bool, args: any...) -> bool?

Argument and Return information

Arguments

# 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

Returns

# 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.DebugDeprecated

shared link
melon.DebugDeprecated()

Warn that the function being called is deprecated

melon.DebugHook

shared link
melon.DebugHook(enabled?: bool, hook: string, fn: function)

Argument and Return information

Arguments

# 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

shared link
melon.DebugID(id: string)

Argument and Return information

Arguments

# Name Type Description
1 id string The string to make unique
Makes an identifier unique only after debugging This is useful for RenderTarget or Material names where you want to create a new one every refresh

melon.DebugKeybind

shared link
melon.DebugKeybind(key: KEY_, fn: function)

Argument and Return information

Arguments

# 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

shared link
melon.DebugNamed(name: string, fn: func, va: any...)

Argument and Return information

Arguments

# 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

shared link internal
melon.DebugNewFileDetected(f: string)

Argument and Return information

Arguments

# Name Type Description
1 f string The file name

melon.DebugOnce

shared link
melon.DebugOnce(f: func, clr?: bool, args: any...) -> bool?

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.DebugPanel(name: string, fun: func)

Argument and Return information

Arguments

# 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

shared link
melon.DebugPanel2(name: string, fun: func)

Argument and Return information

Arguments

# 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.DebugPanel2_HookPaint

shared link internal
melon.DebugPanel2_HookPaint()

melon.DebugPanel2_UnHookPaint

shared link internal
melon.DebugPanel2_UnHookPaint()

melon.DebugPlayer

shared link
melon.DebugPlayer(bots: bool) -> Player

Argument and Return information

Arguments

# Name Type Description
1 bots bool If true, include bots in the search

Returns

# Name Type Description
1 player Player The first player on the server thats superadmin

Gets a player for debug use

melon.DebugRun

shared link
melon.DebugRun(id: string, name: string, args: any...) -> any...

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 ret any... Any return values

Runs a Hook debug

melon.DebugSlider

shared link
melon.DebugSlider(fn: function, speed: number)

Argument and Return information

Arguments

# 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

shared link
melon.DebugWrap(fn: func) -> func

Argument and Return information

Arguments

# Name Type Description
1 fn func Function to wrap Debug around

Returns

# Name Type Description
1 fn func Wrapped function

Wraps a function in Debug, equal to doing:

local x = function(...) melon.Debug(f, _, ...) end  

melon.DefineNewBehavior

shared link internal
melon.DefineNewBehavior()

Weird experiment thats not really used, dont use.

melon.DrawAvatar

shared link
melon.DrawAvatar(stid: string, x: number, y: number, w: number, h: number) -> bool

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.DrawBlur(panel: panel, localX: number, localY: number, w: number, h: number, passes: number)

Argument and Return information

Arguments

# 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

shared link
melon.DrawImage(url: string, x: number, y: number, w: number, h: number) -> bool

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.DrawImageRotated(url: string, x: number, y: number, w: number, h: number, rot: number) -> bool

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.DrawPanelBlur(panel: panel, passes: type)

Argument and Return information

Arguments

# 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

shared link
melon.Find(iter: func, t: table, fn: func) -> any

Argument and Return information

Arguments

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

Returns

# 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

shared link
melon.Font(size: number, font: string, weight: number) -> string

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.FontGenerator(font: string) -> melon.FontGeneratorObject

Argument and Return information

Arguments

# Name Type Description
1 font string Font name for the generator to use

Returns

# Name Type Description
1 gen melon.FontGeneratorObject [melon.FontGeneratorObject] that has the given font
Creates a melon.FontGeneratorObject, an object that allows you to use the font system to consistently create fonts of the same font without constant config indexing.

melon.Format

shared link

[!NOTE]
This is an alias of melon.string.Format

melon.GenerateSuperellipse

shared link
melon.GenerateSuperellipse(n: number, x: number, y: number, w: number, h: number, resolution: number) -> table

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.GenerateSuperellipseMesh(n: number, x: number, y: number, w: number, h: number, resolution: number) -> IMesh

Argument and Return information

Arguments

# 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

Returns

# 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

shared link internal
melon.GetPlayerAvatar(stid64: string) -> IMaterial

Argument and Return information

Arguments

# Name Type Description
1 stid64 string SteamID64 of the players avatar youd like to get

Returns

# 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

shared link
melon.GradientBuilder(id: any, colors: table) -> melon.GradientBuilderObj

Argument and Return information

Arguments

# Name Type Description
1 id any The identifier for the builder
2 colors table A sequential table of {step:number, color:Color}, optional

Returns

# Name Type Description
1 builder melon.GradientBuilderObj The gradient builder object
Creates a melon.GradientBuilderObj object The following example creates an image that looks like: !invalidlink(img)(https://i.imgur.com/Nno9xEz.png)
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

shared link
melon.Grid(w: number, h: number) -> melon.GridObject

Argument and Return information

Arguments

# Name Type Description
1 w number Width to create the grid as
2 h number Height to create the grid as

Returns

# Name Type Description
1 grid melon.GridObject Grid object that was created

Creates a melon.GridObject

melon.GroupBy

shared link
melon.GroupBy(iter: func, t: table, fn: func) -> any

Argument and Return information

Arguments

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

Returns

# Name Type Description
1 new any A table of tables, containing the groups.
Loops through `t` using `iter`. `fn` is expected to return a value for each iteration which will be used to group the elements of the `iter`. The returned value is a table whose keys are those returned values from `fn`.

melon.HTTP

shared link
melon.HTTP(data: HTTPRequest)

Argument and Return information

Arguments

# Name Type Description
1 data HTTPRequest Data to execute with

Queues an HTTP request to run whenever available

melon.Image

shared link
melon.Image(url: string, callback: func)

Argument and Return information

Arguments

# 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

shared link
melon.IsPromise(obj: any) -> bool

Argument and Return information

Arguments

# Name Type Description
1 obj any The object to test

Returns

# Name Type Description
1 ispromise bool Is this object a [melon.PromiseObj]

Is the given object a promise?

melon.IsPromiseError

shared link internal
melon.IsPromiseError(obj: any) -> bool

Argument and Return information

Arguments

# Name Type Description
1 obj any Object ot test

Returns

# Name Type Description
1 iserr bool Is this object a [melon.PromiseErrorObj]

Tests if an object is a promise error

melon.JMap

shared link
melon.JMap(iter: func, t: table, fn: func) -> table

Argument and Return information

Arguments

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

Returns

# Name Type Description
1 new table A table with the mapped elements.
Implements the JavaScript style map function. Maps a table to a new table, calling `fn` with every key/value pair.

melon.Join

shared link
melon.Join(iter: func, t: table, sep: string) -> string

Argument and Return information

Arguments

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

Returns

# 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

shared link
melon.KV2VK(tbl: table) -> table

Argument and Return information

Arguments

# Name Type Description
1 tbl table Table to convert

Returns

# 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

shared link
melon.KillAdvise(id: number)

Argument and Return information

Arguments

# Name Type Description
1 id number The advisory ID to kill

Removes the given advisory immediately

melon.LoadDirectory

shared link internal
melon.LoadDirectory()

Loads a directory recursively, for core use

melon.LoadModule

shared link
melon.LoadModule(folder: string)

Argument and Return information

Arguments

# Name Type Description
1 folder string Module folder name to load

Loads a module from modules/ dynamically, reading init and everything else.

melon.Log

shared link
melon.Log(level: number, fmt: string, fmtargs: any...)

Argument and Return information

Arguments

# 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

shared link
melon.MODULE(name: string) -> melon.MODULEOBJ

Argument and Return information

Arguments

# Name Type Description
1 name string Module to get the object of

Returns

# 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

shared link
melon.Map(tbl: table, fn: func) -> table

Argument and Return information

Arguments

# Name Type Description
1 tbl table Table to map
2 fn func Function that takes k,v and returns a new k,v

Returns

# 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

shared link
melon.Material(path: string, opts: string) -> IMaterial

Argument and Return information

Arguments

# 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

Returns

# 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

shared link
melon.NewStream() -> melon.STREAM

Argument and Return information

Returns

# Name Type Description
1 stream melon.STREAM The new stream

Creates a new melon.STREAM object, initialized without any data

melon.Pack

shared link
melon.Pack(args: any...) -> number, table

Argument and Return information

Arguments

# Name Type Description
1 args any... The varargs to pack.

Returns

# 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

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

Argument and Return information

Arguments

# Name Type Description
1 string string Input string
2 flags? table<string, number> Options for flag handling

Returns

# Name Type Description
1 args table<string> Arguments given
2 flags table<string, table<string>> Flags given
Parse command arguments from `concommand.Add` Turns `argstr` into a set of arguments and flags Flags are prefixed with `--` and consume however many arguments are passed or 0 if not specified by the options If no options are given, accepts all

melon.ParseURL

shared link
melon.ParseURL(url: string) -> melon.URL

Argument and Return information

Arguments

# Name Type Description
1 url string The URL to parse

Returns

# Name Type Description
1 url melon.URL The parsed URL object
Parses a string URL into a melon.URL object or nil if it failed This function is slow, cache its results, also its only really designed for http/https URLs

melon.ParseVersion

shared link
melon.ParseVersion(text: string) -> table

Argument and Return information

Arguments

# Name Type Description
1 text string A string of 3 parts separated by .

Returns

# 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

shared link
melon.PostLoad(fn: func)

Argument and Return information

Arguments

# Name Type Description
1 fn func Function to call post load

Call a function post load, needed because of load order issues

melon.ProcessExtras

shared link internal
melon.ProcessExtras()

Processes the extras parameter of a Module Manifest

melon.Profile

shared link
melon.Profile()

Unsure how functional this actually is.

melon.Promise

shared link
melon.Promise(executor: fn) -> melon.PromiseObj

Argument and Return information

Arguments

# Name Type Description
1 executor fn The promise executor function

Returns

# Name Type Description
1 promise melon.PromiseObj The created promise

Creates a promise

melon.PromiseError

shared link internal
melon.PromiseError(options: table) -> melon.PromiseErrorObj

Argument and Return information

Arguments

# Name Type Description
1 options table Object ot test

Returns

# Name Type Description
1 obj melon.PromiseErrorObj The promise error

Creates a melon.PromiseErrorObj

melon.PromiseWithTraceback

shared link internal
melon.PromiseWithTraceback(traceback: string, executor: fn, parent?: melon.PromiseObj) -> melon.PromiseObj

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 promise melon.PromiseObj The created promise

Creates a promise with a user defined traceback

melon.QuickSerialize

shared link
melon.QuickSerialize(tbl: table) -> string

Argument and Return information

Arguments

# Name Type Description
1 tbl table Table to serialize

Returns

# Name Type Description
1 str string Serialized table
Serializes a table very simply, only allows string keys and values format is key::'value;key2::'value2;

melon.Reduce

shared link
melon.Reduce(iter: func, t: table, fn: func, initial_value: any) -> any

Argument and Return information

Arguments

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

Returns

# Name Type Description
1 new any The reduced value.

Performs a reduction on the given iter with the given fn.

melon.ReloadAll

shared link
melon.ReloadAll()

Reloads melonlib, only functions post gamemode loaded

melon.ResolvedPromise

shared link internal
melon.ResolvedPromise() -> melon.PromiseObj

Argument and Return information

Returns

# Name Type Description
1 promise melon.PromiseObj The resolved promise

Creates a resolved promise

melon.RunAllPromises

shared link
melon.RunAllPromises(promises: table)

Argument and Return information

Arguments

# Name Type Description
1 promises table The table of promises

Runs a table of melon.PromiseObjes

melon.SanitizeURL

shared link
melon.SanitizeURL(url: string) -> string

Argument and Return information

Arguments

# Name Type Description
1 url string URL to sanitize

Returns

# Name Type Description
1 new string Sanitized URL

Sanitize a URL for use in filenames, literally only allows alpha characters

melon.Scale

shared link
melon.Scale(numin: number) -> number

Argument and Return information

Arguments

# Name Type Description
1 numin number Number to scale

Returns

# Name Type Description
1 numout number Scaled number

Scales a number based on invalidlink(ScrH) / 1080

melon.ScaleBy

shared link
melon.ScaleBy(by: number) -> func(by: number) -> number

Argument and Return information

Arguments

# Name Type Description
1 by number Number to scale by

Returns

# 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

shared link
melon.ScaleN(numin: number...) -> number...

Argument and Return information

Arguments

# Name Type Description
1 numin number... Vararg numbers to scale

Returns

# Name Type Description
1 numout number... Unpacked scaled numbers

Scales multiple numbers

melon.SpecialFont

shared link
melon.SpecialFont(size: number, FontData) -> string

Argument and Return information

Arguments

# Name Type Description
1 size number Font size
2 FontData FontData Options to give the font

Returns

# Name Type Description
1 name string Font identifier
Same as melon.Font except creates it with a invalidlink(FontData) table instead of a font name. Dont use in rendering hooks as it is exponentially slower

melon.StackOverflowProtection

shared link
melon.StackOverflowProtection(id: any) -> bool?

Argument and Return information

Arguments

# Name Type Description
1 id any Identifier used for tracking

Returns

# 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

shared link
melon.SubTable(tbl: table, from: number, to: number) -> table

Argument and Return information

Arguments

# Name Type Description
1 tbl table Table to get the subtable of
2 from number Starting index
3 to number Ending index

Returns

# 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

shared link
melon.TestGradient() -> melon.GradientBuilderObj

Argument and Return information

Returns

# Name Type Description
1 builder melon.GradientBuilderObj The test gradient

Creates a standardized test gradient

melon.TextGradient

shared link
melon.TextGradient(text: string, font: string, x: number, y: number, colors: table, local_to: Panel, rotation: number)

Argument and Return information

Arguments

# 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

shared link internal
melon.URLExtension(url: string) -> string

Argument and Return information

Arguments

# Name Type Description
1 url string URL to get the file extension of

Returns

# 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

shared link
melon.UnscaledFont(size: number, font: string) -> string

Argument and Return information

Arguments

# Name Type Description
1 size number Font size raw
2 font string Optional, font to base the new font off of

Returns

# Name Type Description
1 name string Font identifier

Same as melon.Font except the size is unscale.

melon.XPack

shared link
melon.XPack(success: bool, args: any...) -> number, table

Argument and Return information

Arguments

# Name Type Description
1 success bool The success value to forward.
2 args any... The varargs to pack.

Returns

# 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. This function also forwards an initial `success` value separately of the rest of the varargs.

melon.__file__

shared link internal
melon.file()

If you dont understand the source for this, dont use it.

melon.__file_contents__

shared link internal
melon.file_contents()

If you dont understand the source for this, dont use it.

melon.__file_state__

shared link internal
melon.file_state()

If you dont understand the source for this, dont use it.

melon.__load

shared link internal
melon.__load()

Loads everything in the library

melon.attr

shared link internal
melon.attr()

Weird experiment thats not really used, dont use.

melon.clr

shared link
melon.clr()

"Clears" the console by spamming newlines, only functions post gamemode loaded

Classes

melon.FontGeneratorObject

shared link

Font Generator Object


shared link

melon.FontGeneratorObject:Unscaled

shared link
melon.FontGeneratorObject:Unscaled(size: number, weight: number) -> string

Argument and Return information

Arguments

# Name Type Description
1 size number Font size
2 weight number Font weight

Returns

# Name Type Description
1 font string Font identifier

Identical to melon.FontGeneratorObject:Font except unscaled


shared link

melon.FontGeneratorObject:Preprocess

shared link
melon.FontGeneratorObject:Preprocess(size: number, font: string, weight: number) -> number, number, string

Argument and Return information

Arguments

# 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

Returns

# 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
Called every time a font is wanted This is to be used to adjust font sizes globally, or whatever else you need

shared link

melon.FontGeneratorObject:Font

shared link
melon.FontGeneratorObject:Font(size: number, weight: number) -> string

Argument and Return information

Arguments

# Name Type Description
1 size number Font size to be scaled
2 weight number Font weight

Returns

# Name Type Description
1 font string Font identifier

Creates a new font with the given size and font from the object

melon.GradientBuilderObj

shared link
A multi-stage gradient builder objects This makes a mesh and keeps a reference to it, make it once


shared link internal

melon.GradientBuilderObj:Init

shared link internal
melon.GradientBuilderObj:Init()


shared link

melon.GradientBuilderObj:Render

shared link
melon.GradientBuilderObj:Render(x: number, y: number, w: number, h: number, ign?: bool)

Argument and Return information

Arguments

# 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


shared link

melon.GradientBuilderObj:Reset

shared link
melon.GradientBuilderObj:Reset() -> self

Argument and Return information

Returns

# Name Type Description
1 self self The gradbuilder

Resets all steps, if you dont do this and you add steps every frame you will cause a crash


shared link

melon.GradientBuilderObj:ColorMod

shared link
melon.GradientBuilderObj:ColorMod(tl: Color, tr: Color, bl: Color, br: Color) -> self

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 self self The gradbuilder

Modifies the color of a certain quadrant of the gradient


shared link

melon.GradientBuilderObj:Alpha

shared link
melon.GradientBuilderObj:Alpha(tl: number, tr: number, bl: number, br: number) -> self

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 self self The gradbuilder
Determines the alpha of the different quadrants Due to how vertexalpha works, this is useless at the moment I'm finding a way to work around this though, potentially with OverrideBlend

shared link

melon.GradientBuilderObj:LocalTo

shared link
melon.GradientBuilderObj:LocalTo(panel: Panel) -> self

Argument and Return information

Arguments

# Name Type Description
1 panel Panel The panel that this gradient is local to

Returns

# Name Type Description
1 self self The gradbuilder
Tells the gradient to render at a position local to this panel Instead of 0,0 being -x,-y, it will be x,y, where x,y is the LocalToScreen pos of the panel

shared link internal

melon.GradientBuilderObj:Build

shared link internal
melon.GradientBuilderObj:Build(x: number, y: number, w: number, h: number)

Argument and Return information

Arguments

# 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
Builds the gradient into an invalidlink(IMesh) and renders it once This function is expensive, not super, but considerably

shared link

melon.GradientBuilderObj:Invalidate

shared link
melon.GradientBuilderObj:Invalidate()

Invalidates the current mesh, causing it to rebuild


shared link

melon.GradientBuilderObj:Material

shared link
melon.GradientBuilderObj:Material() -> IMaterial

Argument and Return information

Returns

# Name Type Description
1 mat IMaterial The material of the gradient

Renders the gradient to a material and returns it


shared link

melon.GradientBuilderObj:Step

shared link
melon.GradientBuilderObj:Step(perc: number, color: Color) -> self

Argument and Return information

Arguments

# Name Type Description
1 perc number The % of where this step is
2 color Color The color of this step

Returns

# 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%  

shared link

melon.GradientBuilderObj:Vertical

shared link
melon.GradientBuilderObj:Vertical(vertical: bool) -> self

Argument and Return information

Arguments

# Name Type Description
1 vertical bool Vertical (true) or horizontal (false)

Returns

# Name Type Description
1 self self The gradbuilder

Should this gradient be top to bottom instead of left to right?


shared link

melon.GradientBuilderObj:ToCSS

shared link
melon.GradientBuilderObj:ToCSS() -> string

Argument and Return information

Returns

# Name Type Description
1 css string The css repr

Generates a linear-gradient() CSS function call that correlates to this gradient ingame

melon.GridObject

shared link

Grid Object Class


shared link

melon.GridObject:Increment

shared link
melon.GridObject:Increment(x: number, y: number)

Argument and Return information

Arguments

# Name Type Description
1 x number X to get
2 y number Y to get

Increments the value at the given coord


shared link

melon.GridObject:GetSize

shared link
melon.GridObject:GetSize() -> number, number

Argument and Return information

Returns

# Name Type Description
1 w number Width of the object
2 h number Height of the object

Get the size of the grid


shared link

melon.GridObject:Set

shared link
melon.GridObject:Set(x: number, y: number, val: any)

Argument and Return information

Arguments

# 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


shared link

melon.GridObject:SetSize

shared link
melon.GridObject:SetSize(w: number, h: number)

Argument and Return information

Arguments

# Name Type Description
1 w number Width to set
2 h number Height to set

Set the size of the grid


shared link

melon.GridObject:Update

shared link
melon.GridObject:Update()

Updates the grid object


shared link

melon.GridObject:Get

shared link
melon.GridObject:Get(x: number, y: number) -> any

Argument and Return information

Arguments

# Name Type Description
1 x number X to get
2 y number Y to get

Returns

# Name Type Description
1 val any Value of the coord

Gets a value at the given coords

melon.MODULEOBJ

shared link

Defines a melonlib module

Accessors

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

melon.PromiseErrorObj

shared link internal

Describes an error returned from a promise

melon.PromiseObj

shared link

A promise object


shared link

melon.PromiseObj:Next

shared link
melon.PromiseObj:Next(success: fn, failure: fn) -> self

Argument and Return information

Arguments

# Name Type Description
1 success fn Function to call on success
2 failure fn Function to call on failure

Returns

# Name Type Description
1 self self The PromiseObj

Attaches a success/and or failure handler.


shared link

melon.PromiseObj:Cancel

shared link
melon.PromiseObj:Cancel()

Marks the Promise as cancelled, and cancels all consuming Promises.

melon.STREAM

shared link

Simple way to pass around a mutable string builder


shared link

melon.STREAM:WriteLn

shared link
melon.STREAM:WriteLn(data: string) -> self

Argument and Return information

Arguments

# Name Type Description
1 data string The string to write to the buffer

Returns

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


shared link

melon.STREAM:Write

shared link
melon.STREAM:Write(data: string) -> self

Argument and Return information

Arguments

# Name Type Description
1 data string The string to write to the buffer

Returns

# Name Type Description
1 self self
Appends a string to the end of the buffer, uses the concatenation operator so if youre using this for tables/objects remember to override this!

shared link

melon.STREAM:Append

shared link
melon.STREAM:Append(stream: melon.STREAM) -> self

Argument and Return information

Arguments

# Name Type Description
1 stream melon.STREAM The stream to append, gets consumed

Returns

# Name Type Description
1 self self

Appends the given stream to the current stream


shared link

melon.STREAM:Consume()

shared link
melon.STREAM:Consume()() -> string

Argument and Return information

Returns

# Name Type Description
1 str string The written string

Gets the written string and resets the stream,


shared link

melon.STREAM:WriteFmt

shared link
melon.STREAM:WriteFmt(fmt: string, any...) -> self

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 self self

Appends a melon.string.Format formatted string to the end of the buffer

melon.URL

shared link

A URL represented by its component parts

Accessors

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

DataClasses

Note

DataClasses act as regular classes, except that they are virtual constructs used only one place, usually passing to or from functions.

melon.ADVISEINFO

shared link
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

melon.LOGINFO

shared link

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

Enumerations

melon.LOG_

shared link

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

Console Commands

cleer

shared link

"Clears" the console by spamming it with a bunch of empty space

melon_raw_reload

shared link

Reloads melonlib

melon_reload_fonts

client link internal

Resets all fonts forcefully

Hooks

Melon:Debug

shared link
Melon:Debug(time: number)

Argument and Return information

Arguments

# Name Type Description
1 time number When the hook was ran, from os.time.

Called when melon.Debug is called and should run

Melon:DoneLoading

shared link
Melon:DoneLoading()

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  

Melon:DoneLoading:Core

shared link
Melon:DoneLoading:Core()

Called after the core is loaded but before any modules are loaded

Melon:DoneLoading:Modules

shared link
Melon:DoneLoading:Modules()

Called after all modules are done loading

Melon:DoneLoading:PreLoad

shared link
Melon:DoneLoading:PreLoad()

Called before the core any modules are loaded

Melon:NetSchema:Recv

shared link
Melon:NetSchema:Recv(data: table, ply: Player) -> bool

Argument and Return information

Arguments

# 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

Returns

# Name Type Description
1 skip bool If true, skip calling recv on the schema object

Called when a NetSchema message is sent

Melon:NewFileDetected

shared link internal
Melon:NewFileDetected()

Clone this wiki locally