Here is trivial example how to embed LUA into your C/C++ program.
Thre are implemented 2 custom commands available from LUA:
-
Command
uname_machine()that returns machine name from uname(2) system call. -
Command
uptime_seconds()that returns number of seconds from system start (uptime) from sysinfo(2) system call.
NOTE:
There is also TCL Version of this example for comparison.
Tested OS:
echo `lsb_release -sd` - `uname -m`
Debian GNU/Linux 9.9 (stretch) - x86_64Install following required packages:
sudo apt-get install build-essential git valgrind \
liblua5.3-0 liblua5.3-dev liblua5.3-0-dbgOptional: Install Eclipse with CDT (C/C++ development support):
sudo apt-get install eclipse-cdtTODO: import to Eclipse
Just invoke:
makeTo run example just invoke:
make runFollowing examples are run:
print('Hello, world on ' .. uname_machine() .. '!')
print('System uptime is ', uptime_seconds() ,' seconds.')should produce output like:
Hello, world on x86_64!
System uptime is 5257 seconds.
NOTE: That LUA's
To run example with valgrind(1) memory leak detector use:
make valgrindThere should be no leaks reported.
- LUA crash course
- LUA C API - 1st example - unfortunately a bit out-of-date...
- Calling C function from LUA
- Embedding Tcl into C/C++ program