Skip to content

Instantly share code, notes, and snippets.

@leandromoreira

leandromoreira/lua.lua

Last active Apr 21, 2020
Embed
What would you like to do?
-- running luajit in repl will be useful for exploration
-- docker run -it --rm akorn/luajit:2.1-alpine
-- just inspired at
-- https://stackoverflow.com/questions/1426954/split-string-in-lua
function mysplit (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
codeparts = mysplit("luaphase||luacode", "||")
print(codeparts[1])
-- luaphase
print(codeparts[2])
-- luacode
luacode = "a = 0 \n a = a + 1 \n print(a) \n"
luacodefunction = loadstring(luacode)
luacodefunction()
-- 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.