A small presentation of the LIL programming language. Please note that the URLs presented there are not valid anymore. Use http://runtimelegend.com/rep/lil instead of the GitHub URL.
2. What is LIL
LIL is a small programming language
LIL stands for Little Interpreted Language
Focused on being an extension language
Highly dynamic
Minimal syntax
Easy to embed
3. LIL is small
A small core set of functions (about 50)
String handling
Lists
Flow control
etc
A pair of .c and .h files
About 3000 lines of C source code
Could be smaller, but had to be usable :-)
The ”lil” executable is ~40K (Linux x86)
4. Extension languages
A language to write extensions for a host
program
Extensions depend on the program but most
complex programs can be extended via scripts
A wizard for an office application
The logic for a game character
Responses for web requests in a server
A text editor script to convert a set of ”#define” lines
to ”case” lines for C code which return a string with
the constant's name without some prefix
I need this more often than i would want...
5. LIL is an extension language
A host can extend the language by providing
new functions
in LIL everything is done via functions, including
control structures like if, for, while, etc
a function can execute code passed as a function
argument, set a new local or global variable, create
new execution environments, etc
Listen to callbacks for I/O, errors, exit requests,
writing and reading to variables, etc
I/O callbacks can be used to sandbox script
Variable callbacks can expose host variables
6. LIL is highly dynamic
No separate compilation and execution step
The runtime can be modified at any time
New variables can be introduced
New functions can be defined – or redefined
Functions can be renamed – including natives
The runtime can be inspected via reflection
All code and data is stored as strings and
converted to the appropriate type when needed
Code can be generated and is evaluated lazyly
String functions can be used with, e.g. lists
7. LIL has minimal syntax
Everything follows a simple format:
word1 word2 word3 … wordn
For commands the first word is the function name
and the rest are the function arguments
Words are separated by space, but they can
contain special characters and/or be inside
special quotes (single quotes, double quotes,
braces and brackets)
Words can contain spaces or other special
characters, including – if escaped properly –
characters with a special meaning for LIL
8. LIL has minimal syntax (cont.)
Single and double quotes can be used to
include spaces and/or escaping characters
A command inside [ and ] is executed and its
result is used in place of the […]
Anything inside { and } is used as-is
however LIL will count the {s and }s so that they can
be nested
$ followed by a word evalutes to a variable read
this can be changed at runtime to do other things
And that is it. See LIL's readme.txt for details
9. LIL is easy to embed
Uses a readable and permissive license: zlib
Written in C89 with few common C99 features
Can be used as a shared or static library
or just drop the lil.c and lil.h pair in your project
Small API to learn with few simple calls needed
for practical use
Can be used with C and C++ directly and from
languages which support C shared libraries
Import LIL is a project that provides bindings for
Free Pascal and .NET (and others in the future)
13. C API examples
Create and destroy a LIL runtime
lil_t lil = lil_new();
/* do stuff here */
lil_free(lil);
Run some LIL code
lil_free_value(lil_parse(lil,”print hi”,0,0));
Register a custom function
lil_register(lil, ”newfunc”, fnc_newfunc);
fnc_newfunc is defined in the next slide
14. C API examples (cont.)
/* myfunc native function */
LILCALLBACK lil_value_t fnc_myfunc(
lil_t lil, /* lil runtime */
size_t argc, /* number of arguments */
lil_value_t* argv) /* arguments array */
{
size_t i;
printf(”I've got %i arguments:”, (int)argc);
for (i=0; i<argc; i++)
printf(” '%s'n”,
lil_to_string(argv[i]));
return lil_alloc_string(”myfunc result!”);
}
16. More information
LIL at github: https://github.com/badsector/lil
Latest source code
Wiki
Issue db
The readme.txt file in LIL's source code
Everything about LIL
Syntax
Reference
Import LIL: https://github.com/badsector/implil
Bindings for Free Pascal, .NET and maybe others