Skip to content

weberja/lua-cmake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easily embed lua into applications managed with CMake

This is a fork with an edit of the CMakeList.txt to compile lua as c++.

Due to its simplicity and portability, Lua became a popular choice for extending applications through a scripting language. The interpreter is available on most platforms, however, depending on globally installed packages is not always reliable (outdated versions, static vs. dynamic library etc.). As compile times of the interpreter are neglible, embedding it as a git submodule can be preferrable. To simplify the Lua integration into cmake-managed projects, this repository offers two simple facilities.

  • The CMakeLists.txt contains instructions for building the interpreter as a library. It is intended to be used via cmake's add_subdirectory command, and sets up the lua::lib target that can be linked against. Public headers are taken care of and are propagated as a usage requirement.
  • A git clone of the upstream sources is configured as a submodule, such that recursive initialization of this repository pulls them in.

The Lua version pulled in is the current v5.4.1. The library is built as C++ (not C, which is the default possible), with default upstream compiler flags. Whether a shared or static library is built depends on cmake's BUILD_SHARED_LIBS flag. No install target is configured and no standalone executable is built, given the intended use case.

Here's how to use it:

cd path/to/your/project

git submodule add https://github.com/lubgr/lua-cmake external/lua

# Necessary to automatically pull the upstream Lua sources:
git submodule update --init --recursive external/lua

In the CMakeLists.txt of your application, add

add_subdirectory(external/lua)

target_link_libraries(yourTarget PRIVATE lua::lib)

That's it. Further integration with a library to facilitate the bindings (e.g. sol2) is straightfoward. To use sol with lua compiled as c++ you need to include sol the folowing way:

#define SOL_ALL_SAFETIES_ON 1
#define SOL_USING_CXX_LUA 1
#include <sol/sol.hpp>

About

Embed lua with CMake as C++

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • CMake 100.0%