Skip to content

hipBali/vclua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vclua

Gui library for lua

Version 1.0.0

Made with Lazarus version 3.2


Binary releases at sourceforge (win32, win64, linux)

Lua 5.1-5.4 and Luajit

vclua binaries or from vt-form distributives (only Luajit/5.4)


Free Pascal -> Lua generator

Supported features

Types

Automatic inference from source files:

  1. basic types
  2. enums, sets, chars are represented as Lua strings, also TShortCut if possible
  3. dynamic arrays are represented as Lua arrays
  4. event procedures (to set/get properties)
  5. type aliases

Configurable list of LCL and other classes

  1. supported classes with constructors with 0 or 1 parameters
  2. if the class isn't in that list, only its published properties are supported
  3. additional functions can be added
  4. global variables can be exported for use in Lua
  5. the object pointer is stored in the field Handle
  6. rule of thumb: LCL class T<name> would be available as <name> in Lua
  7. Strings can be set as a Lua array of strings
  8. Collection can be set as a Lua array of CollectionItem or a Lua array of tables of properties of those items

Records: TPoint, TRect, TSize, TTextStyle

  • record fields can be of any casing when passing from Lua to Free Pascal
  • to set TPoint, TRect, TSize values in Free Pascal one needs to pass all of the fields in Lua
  • to set TTextStyle one can pass any subset of fields, rest will be Defaulted

Unsupported types:

  1. records not explicitly mentioned
  2. event functions
  3. procedural types for method parameters
  4. class references
  5. object variables
  6. list

Language features

  1. published properties (any casing is supported)
  2. public properties
  3. public and protected event procedures
  4. public variables
  5. array properties
  6. functions and procedures, also class functions and procedures
  7. overloaded methods are implemented with numeric suffix
  8. each method with var parameters is provided twice to be called either without those parameters (since they are used as out), or with them (for TCustomDrawGrid.DefaultDrawCell, TCustomListBox.MeasureItem, ...)
  9. optional parameters
  10. inheritance (everything generated for the class is available for instances of class descendants)
  11. manual typechecking (is)
  12. exceptions are transformed into Lua errors

Unsupported class methods are specified in exclude. Reference property and enumerators are not supported.

Documentation

Examples These examples also serve as tests

Tips, tricks and tools Tools in that repo can serve as complicated examples of using VCLua.

Programming

Class reference


Compiling vclua library

Prepare source code

cd vclua/source-generator

For Windows version you'll need to apply the patch to avoid errors like this

Just replace original file with the provided file or do in Git Bash:

patch --binary /f/Work/Dev/lazarus2/lcl/interfaces/win32/win32object.inc patch/win32object.inc.patch

Add your components

If you want to add new component source to the generated source codes (see src/components) you must use the source code parser/generator tool. First configure the fpc and lazarus source directories, with editing the file lua_make/config.lua

-- linux
local LAZPATH = "/usr/share/lazarus/3.2/"
local FPCSOURCE = "/usr/share/fpcsrc/3.2.2/"
-- windows
local LAZPATH = "f:/Work/Dev/lazarus3/"
local FPCSOURCE = LAZPATH.."fpc/3.2.2/source/"

run the fpc source parser/generator tool

lua lua_make/import.lua true

Set Lua version

check and set the desired lua version at the vcl.lpi file

<CustomOptions Value="-dLUA54"/>

or if you want use with LuaJit then set the compiler directive to

<CustomOptions Value="-dLUA51
-dLUAJIT"/>

Compile source code

open the project in Lazarus and do Run - Clean up and build, or go to the vclua directory and run lazbuild

cd vclua
-- linux
lazbuild -B vcl-linux.lpi
-- windows
lazbuild -B vcl.lpi

If added components won't compile

Check and update the following files: VarTypes, component exclude file inside source-generator/exclude, classdef.lua, LuaProxy.pas

Install library

-- linux
sudo mkdir /usr/local/lib/lua/5.x/vcl
sudo cp libcore.so /usr/local/lib/lua/5.x/vcl/core.so
-- windows
copy core.dll my_lua_libs/vcl/core.dll

vcl folder should end up inside one of the package.cpath folders

Maybe create docs

lua lua_make/import.lua true true

This uses the installed library to get published properties.