Skip to content

Commit

Permalink
Merge pull request RobLoach#33 from RobLoach/fix-structs
Browse files Browse the repository at this point in the history
Update structs
  • Loading branch information
RobLoach authored May 8, 2020
2 parents a79045d + ef014df commit c46ea5e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
path = vendor/raylib
url = https://github.com/raysan5/raylib.git
[submodule "vendor/lua-5.3.5"]
path = vendor/lua-5.3.5
path = vendor/lua
url = https://github.com/lua/lua.git
108 changes: 54 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,67 @@ if (WIN32)
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
endif()

# raylib
find_package(raylib 3.0.0)
if (NOT raylib_FOUND)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games
add_subdirectory(vendor/raylib)
endif()

# Lua
set(LUA_DIR vendor/lua-5.3.5)
set(LUA_SRC
${LUA_DIR}/lapi.c
${LUA_DIR}/lcode.c
${LUA_DIR}/lctype.c
${LUA_DIR}/ldebug.c
${LUA_DIR}/ldo.c
${LUA_DIR}/ldump.c
${LUA_DIR}/lfunc.c
${LUA_DIR}/lgc.c
${LUA_DIR}/llex.c
${LUA_DIR}/lmem.c
${LUA_DIR}/lobject.c
${LUA_DIR}/lopcodes.c
${LUA_DIR}/lparser.c
${LUA_DIR}/lstate.c
${LUA_DIR}/lstring.c
${LUA_DIR}/ltable.c
${LUA_DIR}/ltm.c
${LUA_DIR}/lundump.c
${LUA_DIR}/lvm.c
${LUA_DIR}/lzio.c
${LUA_DIR}/lauxlib.c
${LUA_DIR}/lbaselib.c
${LUA_DIR}/lcorolib.c
${LUA_DIR}/ldblib.c
${LUA_DIR}/liolib.c
${LUA_DIR}/lmathlib.c
${LUA_DIR}/loslib.c
${LUA_DIR}/lstrlib.c
${LUA_DIR}/ltablib.c
${LUA_DIR}/lutf8lib.c
${LUA_DIR}/loadlib.c
${LUA_DIR}/linit.c
)
add_library(lua STATIC ${LUA_SRC})
target_compile_definitions(lua PRIVATE LUA_COMPAT_5_2)
target_include_directories(lua INTERFACE ${LUA_DIR})

# Sol2
set(SOL2_DIR vendor/sol2)
add_library(sol2 INTERFACE)
target_include_directories(sol2 INTERFACE ${SOL2_DIR}/include/)

# Options
option(BUILD_BIN "Binary" ON)
option(BUILD_EXAMPLES "Examples" ON)

add_subdirectory(include)
add_subdirectory(lib)

if (BUILD_BIN)
# raylib
find_package(raylib 3.0.0)
if (NOT raylib_FOUND)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games
add_subdirectory(vendor/raylib)
endif()

# Lua
set(LUA_DIR vendor/lua)
set(LUA_SRC
${LUA_DIR}/lapi.c
${LUA_DIR}/lcode.c
${LUA_DIR}/lctype.c
${LUA_DIR}/ldebug.c
${LUA_DIR}/ldo.c
${LUA_DIR}/ldump.c
${LUA_DIR}/lfunc.c
${LUA_DIR}/lgc.c
${LUA_DIR}/llex.c
${LUA_DIR}/lmem.c
${LUA_DIR}/lobject.c
${LUA_DIR}/lopcodes.c
${LUA_DIR}/lparser.c
${LUA_DIR}/lstate.c
${LUA_DIR}/lstring.c
${LUA_DIR}/ltable.c
${LUA_DIR}/ltm.c
${LUA_DIR}/lundump.c
${LUA_DIR}/lvm.c
${LUA_DIR}/lzio.c
${LUA_DIR}/lauxlib.c
${LUA_DIR}/lbaselib.c
${LUA_DIR}/lcorolib.c
${LUA_DIR}/ldblib.c
${LUA_DIR}/liolib.c
${LUA_DIR}/lmathlib.c
${LUA_DIR}/loslib.c
${LUA_DIR}/lstrlib.c
${LUA_DIR}/ltablib.c
${LUA_DIR}/lutf8lib.c
${LUA_DIR}/loadlib.c
${LUA_DIR}/linit.c
)
add_library(lua STATIC ${LUA_SRC})
target_compile_definitions(lua PRIVATE LUA_COMPAT_5_2)
target_include_directories(lua INTERFACE ${LUA_DIR})

# Sol2
set(SOL2_DIR vendor/sol2)
add_library(sol2 INTERFACE)
target_include_directories(sol2 INTERFACE ${SOL2_DIR}/include/)

# Add the binary.
add_subdirectory(bin)
endif()

Expand Down
14 changes: 13 additions & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
add_executable(raylib-lua-sol raylib-lua-sol.cpp)

target_compile_definitions(raylib-lua-sol PUBLIC -DLUA -DPHYSAC_NO_THREADS)

set_target_properties(raylib-lua-sol PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
)

target_link_libraries(raylib-lua-sol
libraylib-lua-sol
raylib-lua-sol-hpp
raylib
lua
sol2
)

target_include_directories(raylib-lua-sol PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/lua
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib/src
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/sol2/include
)
8 changes: 5 additions & 3 deletions include/raylib-lua-sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void raylib_lua_sol_structs(sol::state& lua) {
return TextFormat("{x: %02.02f, y: %02.02f, width: %02.02f, height: %02.02f}", r.x, r.y, r.width, r.height);
}
);

lua.new_usertype<Color>("Color",
sol::call_constructor, sol::factories(
[](){
Expand Down Expand Up @@ -102,7 +101,10 @@ void raylib_lua_sol_structs(sol::state& lua) {
),
"x", &Vector3::x,
"y", &Vector3::y,
"z", &Vector3::z);
"z", &Vector3::z,
sol::meta_function::to_string, [](Vector3& v) {
return TextFormat("{x: %02.02f, y: %02.02f, z: %02.02f}", v.x, v.y, v.z);
});
lua.new_usertype<Vector4>("Vector4",
sol::call_constructor, sol::factories(
[](){
Expand Down Expand Up @@ -1064,11 +1066,11 @@ void raylib_lua_sol_function_wrappers(sol::state &lua) {
}

void raylib_lua_sol(sol::state& lua) {
raylib_lua_sol_structs(lua);
raylib_lua_sol_color(lua);
raylib_lua_sol_enums(lua);
raylib_lua_sol_functions(lua);
raylib_lua_sol_function_wrappers(lua);
raylib_lua_sol_structs(lua);
}

#endif // RAYLIB_LUA_SOL_
25 changes: 0 additions & 25 deletions lib/CMakeLists.txt

This file was deleted.

11 changes: 0 additions & 11 deletions lib/libraylib-lua-sol.cpp

This file was deleted.

7 changes: 1 addition & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
add_test(
NAME raylib-lua-sol-tests
COMMAND raylib-lua-sol
raylib-lua-sol-tests.lua)

file(
COPY raylib-lua-sol-tests.lua
DESTINATION .
)
${CMAKE_CURRENT_SOURCE_DIR}/raylib-lua-sol-tests.lua)
16 changes: 5 additions & 11 deletions tests/raylib-lua-sol-tests.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
local function describe(name, descriptor)
local errors = {}
local successes = {}

function it(spec_line, spec)
local status = xpcall(spec, function (err)
table.insert(errors, string.format("\t%s\n\t\t%s\n", spec_line, err))
end)

if status then
table.insert(successes, string.format("\t%s\n", spec_line))
end
end

local status = xpcall(descriptor, function (err)
table.insert(errors, err)
end, it)

print(name)

if #successes > 0 then
print('Successes:')
print(table.concat(successes))
end

if #errors > 0 then
print('Failures:')
print(table.concat(errors))
Expand All @@ -40,14 +34,14 @@ describe('raylib-lua-sol Tests', function (it)
assert(FLAG_FULLSCREEN_MODE == 2, "FLAG_FULLSCREEN_MODE should equal 2")
end)

-- TODO: Fix Rectangle
it('Structs', function ()
local rect = Rectangle(10, 20, 30, 40)
--print(rect)
--assert(rect.width == 10, "Rectangle width should be 10")
assert(rect.width == 30, "Rectangle width should be 30")
rect.width = 500
--print(rect)
--assert(rect.width == 500, "Rectangle width should be 30")
assert(rect.width == 500, "Rectangle width should be 500")

local vec = Vector2(30, 40)
assert(vec.x == 30)
end)

it ('Color', function ()
Expand Down

0 comments on commit c46ea5e

Please sign in to comment.