Files
Mush-Soundpack/cosmic rage/lua/string_indexing.lua
2025-07-01 23:28:00 +03:00

25 lines
402 B
Lua

--[[
string_indexing.lua
If you install this, then you can index into strings, like this:
require "string_indexing"
a = "nick"
print (a [3]) --> c
--]]
getmetatable ("").__index = function (str, i)
if (type (i) == "number") then
return string.sub (str, i, i) -- index into str
end -- if
return string [i] -- fallback (eg. string.match)
end -- function