Skip to content

Instantly share code, notes, and snippets.

--[[
NetStream - 2.0.1
https://github.com/alexgrist/NetStream/blob/master/netstream2.lua
Alexander Grist-Hucker
http://www.revotech.org
Credits to:
thelastpenguin for pON.
https://github.com/thelastpenguin/gLUA-Library/tree/master/pON
--[[
local str = "Hi"
print(ChangeLine(str, "OwO", 1)) -- output: OwO
print(ChangeLine(str, " Srlion!", 1, true)) -- output: Hi Srlion!
print(ChangeLine(str, "Srlion ", 1, false)) -- output: Srlion Hi
]]
-- Localize functions so accessing them becomes more faster
local sub = string.sub
local rep = string.rep
local times = {"w", 604800, "d", 86400, "h", 3600, "m", 60, "s", 1}
for i = 1, # times - 2, 2 do
times[i] = times[i] .. (" ")
end
local math_floor = math.floor
function FormatTime(seconds)
if (seconds <= 0) then
return seconds .. "s"
end
local str = ""
-- af needs to be remade because string.Split is slow
GetCaretLine = function(s)
local caretPos = s:GetCaretPos() + 1
local splittedText = s:GetText():Split("\n")
local len = 0
for k, v in ipairs(splittedText) do
len = len + #v + 1
if (caretPos <= len) then
local sv_load = function(file)
if (SERVER) then
return include(file)
end
end
local cl_load = function(file)
if (SERVER) then
AddCSLuaFile(file)
else
--[[
mysql - 1.0.2
A simple MySQL wrapper for Garry's Mod.
Alexander Grist-Hucker
http://www.alexgrist.com
https://github.com/alexgrist/GLua-MySQL-Wrapper/blob/master/mysql.lua
--]]
--[[
--[[
requires:
async
https://github.com/Srlion/sr-stuff/blob/master/lua/async.lua
netstream
https://github.com/alexgrist/NetStream/blob/master/netstream2.lua
OR
https://github.com/Srlion/sr-stuff/blob/master/lua/netstream.lua
--[[
https://github.com/yongkangchen/lua-await/blob/master/sync.lua
MIT License
Copyright (c) 2016 Yongkang Chen lx1988cyk#gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
local COLOR_KEY = Color(0, 255, 0)
local COLOR_VALUE = Color(255, 255, 0)
local COLOR_DEFAULT = Color(255, 255, 255)
local COLOR_DOTS = Color(0, 0, 255)
do
local MsgC = MsgC
local istable = istable
local isstring = isstring
local tostring = tostring