Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Last active April 21, 2020 12:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save leandromoreira/cbae75b769d106055da395496f5b2920 to your computer and use it in GitHub Desktop.
-- 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