Compile Flags Lua C Embed

Simple Lua + C template. GitHub Gist: instantly share code, notes, and snippets. Example of embedding Lua in C. GitHub Gist: instantly share code, notes, and snippets. The default Lua Makefile attempts to use setjmp/longjmp in ldo.c when on Linux. I disabled the LUAUSELINUX flag for compiling the object files, but this caused an issue with tmpnam in loslib.c (mkstemp is available in Cosmopolitan). I changed the Lua source to use setjmp/longjmp. Or read about the C API online in the 1st edition of PIL: PIL1 - The C API An introductory video on embedding Lua in C: Embedding Lua in C #1 A tutorial for embedding Lua in C: Embedding Lua in C Enabling API checking. By default, the Lua C API does almost no sanity checking of arguments passed to it.

readme.md
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(clue)
set(CMAKE_CXX_FLAGS '${CMAKE_CXX_FLAGS} -std=c++11')
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY '${PROJECT_SOURCE_DIR}/bin/')
include('lua.cmake')
set(SOURCE_FILES main.cpp)
add_executable(clue ${SOURCE_FILES})
add_dependencies(clue ${Lua_TARGET})
target_link_libraries(clue ${LUA_LIBRARIES})
lua.cmake
include(ExternalProject)
if(WIN32)
set(cExtraFlags)
set(cxxExtraFlags)
else()
set(cExtraFlags -w)
set(cxxExtraFlags -w)
endif()
# a cmakeified version of lua
ExternalProject_Add(lua
URL https://github.com/LuaDist/lua/archive/5.2.3.tar.gz
URL_MD5 710bba91186bb672b829cd05d78b614d
CMAKE_ARGS -Wno-dev
CMAKE_CACHE_ARGS
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
'-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}${cxxExtraFlags}'
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
'-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}${cExtraFlags}'
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
ExternalProject_Get_Property(lua INSTALL_DIR)
ExternalProject_Get_Property(lua BINARY_DIR)
if(WIN32)
set(LUA_LIBRARIES debug ${BINARY_DIR}/Debug/lua.lib
optimized ${BINARY_DIR}/Release/lua.lib)
else()
set(LUA_LIBRARIES ${BINARY_DIR}/liblua.a)
endif()
set(lua_include_dir ${INSTALL_DIR}/include)
include_directories(SYSTEM${lua_include_dir})
link_directories(${BINARY_DIR})
set(Lua_TARGET lua)
Compile flags lua c embed fileCompile Flags Lua C Embed
main.cpp
#include<iostream>
#include<lua.hpp>
intmain() {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
constchar *lc = 'print('Hello from lua!');';
luaL_loadbuffer(L, lc, strlen(lc), 0);
lua_pcall(L, 0, 0, 0);
lua_close(L);
}

Compile Flags Lua C Embed File

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment