A metatable can be defined like
local t = setmetatable({}, {
__tostring = function() return 'custom tostring behavior!' end
})
Here are the metamethods that you can define, and their behavior
function replace_capture_by_capture_number2(str, what, with, ...) | |
-- the elipsis (vararg) represents a list of integers denoting the number of the what instance in the str | |
-- if the what instance number is out of scope or it isn't found, returns the original str | |
local t = {...} | |
local i = 0 | |
local function repl() | |
i=i+1 | |
for _, v in ipairs(t) do | |
if v == i then return with end | |
end |
[Serializable] | |
public enum VKeys | |
{ | |
KEY_0 = 0x30, //0 key | |
KEY_1 = 0x31, //1 key | |
KEY_2 = 0x32, //2 key | |
KEY_3 = 0x33, //3 key | |
KEY_4 = 0x34, //4 key | |
KEY_5 = 0x35, //5 key | |
KEY_6 = 0x36, //6 key |
--[[ | |
* ReaScript Name: Save_FX_Preset | |
* Lua script for Cockos REAPER | |
* Author: EUGEN27771 | |
* Author URI: http://forum.cockos.com/member.php?u=50462 | |
* Licence: GPL v3 | |
* Version: 1.04 | |
* Mod by X-Raym | |
https://gist.github.com/X-Raym/448e8afea7d91bce96b520ca12ddc698#file-gen_save-preset-for-last-touched-fx-x-raym-mod-lua | |
https://forum.cockos.com/showthread.php?t=178127 |
function Esc(str) | |
if not str then return end -- prevents error | |
-- isolating the 1st return value so that if vars are initialized in a row outside of the function the next var isn't assigned the 2nd return value | |
local str = str:gsub('[%(%)%+%-%[%]%.%^%$%*%?%%]','%%%0') | |
return str | |
end | |
function insert_string_at_specific_position1(src_str, insert_str, pos_idx, move) | |
-- relies on Esc() function | |
-- returns nil if pos_idx is greater than src_str length |
function remove_all_bar_some(str, ...) | |
-- the elipsis represents both literals and char classes | |
-- mind special characters which must be escaped as arguments | |
local keep = {...} | |
-- the table doesn't have to be passed as argument | |
-- because gsub doesn't seem to support functions with more than 1 argument | |
local function thin_out(c) | |
return function(c) | |
for _, char in ipairs(keep) do | |
if c == char or c:match(char) |
function replace_capture_by_capture_number(str, what, with, ...) | |
-- the elipsis represents a list of integers denoting the number of the what instance in the str | |
-- if the what instance number is out of scope or it isn't found, returns the original str | |
-- refer to https://gist.github.com/Buy-One/eb033b716e7692e0d856779257cb3a96 | |
-- for alternatives using string.gsub() | |
local inst_t = {...} | |
local t = {} | |
local i = 1 | |
while i < #str do -- collect indices at which the what instances start | |
local s, e = str:find(what, i) |
function sort_notes_by_name(t, wantReverse) -- t is an array containing note names, wantReverse is boolean | |
-- the notes must use # and b for sharps and flats | |
-- the notes must be capitalized to distinguish between B and flat sign b | |
local pat = '[%-%d]+' | |
table.sort(t, function(a,b) return a:match(pat) < b:match(pat) end) -- sort by octave | |
local oct = -10 -- a value lower than the lowest octave number to be able to detect the 1st lowest and so forth | |
local table_len = #t -- to be used in removing all separate note fields |
function shuffle_array(t, places, backward) -- places integer, backward boolean | |
-- number of places backward = #t - places forward and vice versa, the results will be identical | |
if places == #t then return end -- because the order will end up being the same | |
local i = 0 | |
if not backward then | |
local last = t[#t] -- store to assign to the 1st field | |
repeat | |
for i = #t,1,-1 do | |
if i < #t then t[i+1] = t[i] end | |
end |
People
:bowtie: |
😄 :smile: |
😆 :laughing: |
---|---|---|
😊 :blush: |
😃 :smiley: |
:relaxed: |
😏 :smirk: |
😍 :heart_eyes: |
😘 :kissing_heart: |
😚 :kissing_closed_eyes: |
😳 :flushed: |
😌 :relieved: |
😆 :satisfied: |
😁 :grin: |
😉 :wink: |
😜 :stuck_out_tongue_winking_eye: |
😝 :stuck_out_tongue_closed_eyes: |
😀 :grinning: |
😗 :kissing: |
😙 :kissing_smiling_eyes: |
😛 :stuck_out_tongue: |