Skip to content

Instantly share code, notes, and snippets.

@imring
Last active July 24, 2018 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imring/23f374c2399cd82e6422ea4631e05738 to your computer and use it in GitHub Desktop.
Save imring/23f374c2399cd82e6422ea4631e05738 to your computer and use it in GitHub Desktop.
script_name 'compile_lua'
script_author'imring'
imgui = require 'imgui'
encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
compiler_lua = imgui.ImBool(false)
code_buffer = imgui.ImBuffer('print("Hello world!")', 0xFFFFFF)
print_bool = imgui.ImBool(false)
messages = {}
function apply_styles()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
style.WindowRounding = 1.5
colors[clr.TitleBg] = ImVec4(0.0, 0.0, 0.0, 0.6)
colors[clr.TitleBgActive] = ImVec4(0.0, 0.0, 0.0, 0.7)
colors[clr.TitleBgCollapsed] = ImVec4(0.0, 0.0, 0.0, 0.8)
colors[clr.CloseButton] = ImVec4(0.41, 0.41, 0.41, 0.50)
colors[clr.CloseButtonHovered] = ImVec4(0.98, 0.39, 0.36, 1.00)
colors[clr.CloseButtonActive] = ImVec4(0.98, 0.39, 0.36, 1.00)
colors[clr.WindowBg] = ImVec4(0.0, 0.0, 0.0, 0.5)
colors[clr.ScrollbarBg] = ImVec4(0.0, 0.0, 0.0, 0.2)
colors[clr.ScrollbarGrab] = ImVec4(0.8, 0.8, 0.8, 0.3)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.8, 0.8, 0.8, 0.4)
colors[clr.ScrollbarGrabActive] = ImVec4(0.8, 0.8, 0.8, 0.5)
colors[clr.Header] = ImVec4(0.8, 0.8, 0.8, 0.3)
colors[clr.HeaderHovered] = ImVec4(0.8, 0.8, 0.8, 0.4)
colors[clr.HeaderActive] = ImVec4(0.8, 0.8, 0.8, 0.5)
colors[clr.Button] = ImVec4(0.8, 0.8, 0.8, 0.3)
colors[clr.ButtonHovered] = ImVec4(0.8, 0.8, 0.8, 0.4)
colors[clr.ButtonActive] = ImVec4(0.8, 0.8, 0.8, 0.5)
colors[clr.SliderGrabActive] = ImVec4(0.8, 0.8, 0.8, 0.3)
end
apply_styles()
local oprint = print
function cprint(...)
messages[#messages + 1] = table.concat({ ... }, ' ')
end
function main()
while true do wait(0)
if testCheat('CMP') then imgui.Process = not imgui.Process end
end
end
function imgui.OnDrawFrame()
local x, y = getScreenResolution()
imgui.SetNextWindowPos(imgui.ImVec2(x/2, y/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(x/2, y/2), imgui.Cond.FirstUseEver)
imgui.Begin('ImGui Compiler lua', compile_lua)
imgui.Text('ImGui Compiler lua by imring.')
if imgui.Checkbox('Print to log\'s', print_bool) then print = print_bool.v and cprint or oprint end
imgui.BeginChild('console', imgui.ImVec2(0, imgui.GetWindowHeight()/2), true)
imgui.Text('Code')
imgui.SameLine()
if imgui.Button('Compile') then
messages = {}
local code = u8:decode(code_buffer.v)
local a, b = load(code)
if a then
local c, d = pcall(a)
if not c then print(d) end
else print(b) end
end
imgui.InputTextMultiline('##code_buffer', code_buffer, imgui.ImVec2(-0.1, -0.1))
imgui.EndChild()
imgui.BeginChild('logs', imgui.ImVec2(0, 0))
imgui.Text('Log\'s:')
for i, k in ipairs(messages) do
imgui.Text(u8(k))
end
imgui.EndChild()
imgui.End()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment