Add Lua dependencies.

Lua is going to be used for both scene description (it will also provide a YAML importer) and some future expansion in the code. Expect some fun surprises!

(just playing with lua on the main app for now)
This commit is contained in:
Godzil
2020-02-27 17:24:40 +00:00
parent e61382a129
commit 2926166ce6
3 changed files with 51 additions and 6 deletions

View File

@@ -40,13 +40,24 @@ if (ENABLE_COVERAGE)
endif() endif()
# LodePNG don't make a .a or .so, so let's build a library here # LodePNG don't make a .a or .so, so let's build a library here
add_library(LodePNG STATIC) add_library(LodePNG STATIC)
set(LODEPNG_INCLUDE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/external/lodepng) set(LODEPNG_INCLUDE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/external/lodepng)
target_sources(LodePNG PRIVATE external/lodepng/lodepng.cpp external/lodepng/lodepng.h) target_sources(LodePNG PRIVATE external/lodepng/lodepng.cpp external/lodepng/lodepng.h)
ExternalProject_Add(LuaCore
URL "https://www.lua.org/ftp/lua-5.3.5.tar.gz"
URL_HASH SHA1=112eb10ff04d1b4c9898e121d6bdf54a81482447
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/lua
CONFIGURE_COMMAND ""
BUILD_IN_SOURCE True
BUILD_COMMAND make generic
INSTALL_COMMAND ""
)
set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/lua/src")
set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/external/lua/src/liblua.a")
# Main app # Main app
add_subdirectory(source) add_subdirectory(source)

View File

@@ -20,10 +20,10 @@ target_link_libraries(rayonnement LodePNG)
if (USE_OPENMP) if (USE_OPENMP)
target_link_libraries(rayonnement OpenMP::OpenMP_CXX) target_link_libraries(rayonnement OpenMP::OpenMP_CXX)
endif() endif()
# Second we build the main executable
add_executable(dorayme main.cpp) add_executable(dorayme main.cpp)
target_include_directories(rayonnement PUBLIC include ${LODEPNG_INCLUDE_FOLDER}) target_include_directories(rayonnement PUBLIC include ${LODEPNG_INCLUDE_FOLDER} ${LUA_INCLUDE_DIR})
target_link_libraries(dorayme rayonnement) target_link_libraries(dorayme rayonnement ${LUA_LIBRARIES})
if (COVERALLS) if (COVERALLS)
set(COVERAGE_SRCS ${RAY_HEADERS} ${RAY_SOURCES} ${COVERAGE_SRCS} PARENT_SCOPE) set(COVERAGE_SRCS ${RAY_HEADERS} ${RAY_SOURCES} ${COVERAGE_SRCS} PARENT_SCOPE)

View File

@@ -8,10 +8,44 @@
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <math.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
static int l_sin (lua_State *L) {
double d = luaL_checknumber(L, 1); /* get argument */
lua_pushnumber(L, sin(d)); /* push result */
return 1; /* number of results */
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
printf("Hello !\n"); char buff[256];
int error;
lua_State *L = luaL_newstate(); /* opens Lua */
luaL_openlibs(L); /* opens the basic library */
lua_pushcfunction(L, l_sin);
lua_setglobal(L, "mysin");
printf("[0]>");
while (fgets(buff, sizeof(buff), stdin) != NULL)
{
error = luaL_loadstring(L, buff) || lua_pcall(L, 0, LUA_MULTRET, 0);
if (error)
{
fprintf(stderr, "%s\n", lua_tostring(L, -1));
lua_pop(L, 1); /* pop error message from the stack */
}
printf("[%d]>", lua_gettop(L));
}
lua_close(L);
return 0; return 0;
} }