Skip to content

Instantly share code, notes, and snippets.

@vonHabsi
Last active January 30, 2022 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vonHabsi/ab6d6eb23df572207166 to your computer and use it in GitHub Desktop.
Save vonHabsi/ab6d6eb23df572207166 to your computer and use it in GitHub Desktop.
VCLua Samples
-- Q
-- Hello! Beautiful project.
-- Would it be possible to display the output of my Lua script in a simple message box (without opening a form)? If it is possible, could you provide a code example?
-- Thank you in advance.
-- Roland
-- Hi! Thank you.
--
-- If you dont want to use forms you should initialize gui application manually.
-- Here is the example:
--A
VCL = require "vcl"
local lua_out = {}
table.insert(lua_out, "Hello world!");
table.insert(lua_out, "");
table.insert(lua_out, "(messagebox sample)");
-- Don't forget to initialize the gui application!
-- If you dont use any form, the app will not initialized automaticaly
VCL.Application():Initialize()
VCL.ShowMessage(table.concat(lua_out,"\n"));
-- RC Thank you for the answer. Perfect example. With that example and a piece of code taken into the documentation, I could also make this:
VCL = require "vcl"
local lua_out = {}
table.insert(lua_out, "Save file?");
table.insert(lua_out, "");
table.insert(lua_out, "(message sample)");
VCL.Application():Initialize()
answer = VCL.MessageDlg(
table.concat(lua_out,"\n"),
"mtConfirmation",
{"mbYes", "mbNo", "mbCancel"}
)
-- RC
Here is a little tool that I use to clean a Lazarus directory. Now it has a message box. :)
--------------------------------------------------------------------------------
-- Script name: cleaner.lua ----------------------------------------------------
-- Function: searches and deletes a given set of files in the script directory -
-- and its subdirectories ------------------------------------------------------
-- Uses VCLua to show a message ------------------------------------------------
-- Tested with Lua 5.2 ---------------------------------------------------------
-- OS: Windows_NT --------------------------------------------------------------
-- 08/18/14 18:00:19 -----------------------------------------------------------
--------------------------------------------------------------------------------
function listfiles(directory)
local i, t, popen = 0, {}, io.popen
for filename in popen('dir "' .. directory .. '" /a-d /b /l /s'):lines() do
i = i + 1
t[i] = filename
end
return t
end
function filepath(file)
if string.find(file, "\\") then
local r = file
while string.sub(r, #r) ~= "\\" do
r = string.sub(r, 1, -2)
end
return r
else
return ""
end
end
function fileext(file)
if string.find(file, ".", 1, true) then
local r = file
repeat
r = string.sub(r, 2)
until not string.find(r, ".", 1, true)
return "." .. r
else
return ""
end
end
function set(list)
local r = {}
for _, l in ipairs(list) do
r[l] = true
end
return r
end
local s = set(
{
".compiled",
".dbg",
".exe",
".o",
".obj",
".ppu"
}
)
local t = listfiles(filepath(arg[0]))
local n = 0
local max = 20
for i = 1, #t do
if s[fileext(t[i])] then
if os.remove(t[i]) then
n = n + 1
print(t[i])
end
end
end
-- Main program using VCLua
package.cpath = package.cpath .. ";C:\\Atelier\\Lua\\VCLua\\?.dll" -- DLL path
VCL = require "vcl"
VCL.Application():Initialize()
VCL.ShowMessage(n .. " file(s) deleted.")
if answer =="mrYes" then
print("yes")
VCL.ShowMessage("yes")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment