Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Expand Down
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ endif()

add_subdirectory(Source)

if(LUABRIDGE_TESTING)
find_package(GTest)
if(NOT GTest_FOUND)
set(gtest_force_shared_crt ON CACHE BOOL "Use /MD and /MDd" FORCE)
add_subdirectory(third_party/gtest EXCLUDE_FROM_ALL)
add_library(GTest::gtest ALIAS gtest)
endif()
if(LUABRIDGE_SANITIZE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

if(LUABRIDGE_TESTING)
set(gtest_force_shared_crt ON CACHE BOOL "Use /MD and /MDd" FORCE)
add_subdirectory(third_party/gtest EXCLUDE_FROM_ALL)
add_library(GTest::gtest ALIAS gtest)
enable_testing()
add_subdirectory(Tests)
endif()

add_custom_target(Documentation SOURCES
.clang-format
.github/workflows/cmake.yml
CHANGES.md
README.md
Expand Down
10 changes: 5 additions & 5 deletions Manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,12 @@ <h2>2.5 - <span id="s2.5">Function Member Proxies</span></h2>
</p>

<pre>
void scale (float value)
void scale (Vec* v, float value)
{
value->coord [0] *= value;
value->coord [1] *= value;
value->coord [2] *= value;
};
v->coord [0] *= value;
v->coord [1] *= value;
v->coord [2] *= value;
}
</pre>

<p>
Expand Down
2 changes: 1 addition & 1 deletion Source/LuaBridge/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Stack<std::array<T, s>>
luaL_error(L, "array size must be %d ", s);
}

std::array<T, s> array;
std::array<T, s> array = {};

int const absindex = lua_absindex(L, index);
lua_pushnil(L);
Expand Down
17 changes: 10 additions & 7 deletions Source/LuaBridge/Pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ struct Stack<std::pair<T1, T2>>

std::pair<T1, T2> pair;

int const absindex = lua_absindex(L, index);
int const absIndex = lua_absindex(L, index);
lua_pushnil(L);

{
int const next = lua_next(L, absindex);
assert(next != 0);
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
assert(hasNext != 0);
(void) hasNext;

pair.first = Stack<T1>::get(L, -1);
lua_pop(L, 1);
}

{
int const next = lua_next(L, absindex);
assert(next != 0);
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
assert(hasNext != 0);
(void) hasNext;

pair.second = Stack<T2>::get(L, -1);
lua_pop(L, 1);
}

{
int const next = lua_next(L, absindex);
assert(next == 0);
int const hasNext = lua_next(L, lua_absindex(L, absIndex));
assert(hasNext == 0);
(void) hasNext;
}

return pair;
Expand Down
35 changes: 23 additions & 12 deletions Source/LuaBridge/detail/CFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct CFunc
Retrieves functions from metatables and properties from propget tables.
Looks through the class hierarchy if inheritance is present.
*/
static int indexMetaMethod(lua_State* L)
static int indexMetaMethod(lua_State* L) noexcept
{
assert(lua_istable(L, 1) ||
lua_isuserdata(L, 1)); // Stack (further not shown): table | userdata, name
Expand Down Expand Up @@ -112,16 +112,22 @@ struct CFunc
__newindex metamethod for namespace or class static members.
Retrieves properties from propset tables.
*/
static int newindexStaticMetaMethod(lua_State* L) { return newindexMetaMethod(L, false); }
static int newindexStaticMetaMethod(lua_State* L) noexcept
{
return newindexMetaMethod(L, false);
}

//----------------------------------------------------------------------------
/**
__newindex metamethod for non-static members.
Retrieves properties from propset tables.
*/
static int newindexObjectMetaMethod(lua_State* L) { return newindexMetaMethod(L, true); }
static int newindexObjectMetaMethod(lua_State* L) noexcept
{
return newindexMetaMethod(L, true);
}

static int newindexMetaMethod(lua_State* L, bool pushSelf)
static int newindexMetaMethod(lua_State* L, bool pushSelf) noexcept
{
assert(
lua_istable(L, 1) ||
Expand Down Expand Up @@ -183,13 +189,18 @@ struct CFunc

The name of the variable is in the first upvalue.
*/
static int readOnlyError(lua_State* L)
static int readOnlyError(lua_State* L) noexcept
{
std::string s;

s = s + "'" + lua_tostring(L, lua_upvalueindex(1)) + "' is read-only";

return luaL_error(L, s.c_str());
try
{
std::string s;
s = s + "'" + lua_tostring(L, lua_upvalueindex(1)) + "' is read-only";
return luaL_error(L, s.c_str());
}
catch (...)
{
return luaL_error(L, "Property is read-only");
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -308,7 +319,7 @@ struct CFunc
static int f(lua_State* L)
{
assert(isfulluserdata(L, lua_upvalueindex(1)));
typedef int (T::*MFP)(lua_State * L);
typedef int (T::*MFP)(lua_State* L);
T* const t = Userdata::get<T>(L, 1, false);
MFP const& fnptr = *static_cast<MFP const*>(lua_touserdata(L, lua_upvalueindex(1)));
assert(fnptr != 0);
Expand All @@ -322,7 +333,7 @@ struct CFunc
static int f(lua_State* L)
{
assert(isfulluserdata(L, lua_upvalueindex(1)));
typedef int (T::*MFP)(lua_State * L);
typedef int (T::*MFP)(lua_State* L);
T const* const t = Userdata::get<T>(L, 1, true);
MFP const& fnptr = *static_cast<MFP const*>(lua_touserdata(L, lua_upvalueindex(1)));
assert(fnptr != 0);
Expand Down
4 changes: 2 additions & 2 deletions Source/LuaBridge/detail/FuncTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace detail {
(defined(_MSC_VER) && (_MSC_VER >= 1700))
// Do not define LUABRIDGE_THROWSPEC since the Xcode and gcc compilers do not
// distinguish the throw specification in the function signature.
#define LUABRIDGE_THROWSPEC
# define LUABRIDGE_THROWSPEC
#else
// Visual Studio 10 and earlier pay too much mind to useless throw () spec.
//
#define LUABRIDGE_THROWSPEC throw()
# define LUABRIDGE_THROWSPEC throw()
#endif

//==============================================================================
Expand Down
15 changes: 8 additions & 7 deletions Source/LuaBridge/detail/LuaHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ inline void lua_rawsetp(lua_State* L, int idx, void const* p)
lua_rawset(L, idx);
}

#define LUA_OPEQ 1
#define LUA_OPLT 2
#define LUA_OPLE 3
# define LUA_OPEQ 1
# define LUA_OPLT 2
# define LUA_OPLE 3

inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
{
Expand Down Expand Up @@ -66,7 +66,8 @@ inline int get_length(lua_State* L, int idx)
return int(lua_objlen(L, idx));
}

#else
#else // LUA_VERSION_NUM < 502

inline int get_length(lua_State* L, int idx)
{
lua_len(L, idx);
Expand All @@ -75,12 +76,12 @@ inline int get_length(lua_State* L, int idx)
return len;
}

#endif
#endif // LUA_VERSION_NUM >= 502

#ifndef LUA_OK
#define LUABRIDGE_LUA_OK 0
# define LUABRIDGE_LUA_OK 0
#else
#define LUABRIDGE_LUA_OK LUA_OK
# define LUABRIDGE_LUA_OK LUA_OK
#endif

/** Get a table value, bypassing metamethods.
Expand Down
1 change: 0 additions & 1 deletion Source/LuaBridge/detail/LuaRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <iostream>
#include <map>
#include <string>
#include <vector>

namespace luabridge {

Expand Down
16 changes: 8 additions & 8 deletions Source/LuaBridge/detail/Namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class Namespace : public detail::Registrar

//--------------------------------------------------------------------------
template<class U>
Class<T>& addProperty(char const* name, U T::*mp, bool isWritable = true)
Class<T>& addProperty(char const* name, U T::* mp, bool isWritable = true)
{
return addData(name, mp, isWritable);
}
Expand All @@ -589,11 +589,11 @@ class Namespace : public detail::Registrar
Add or replace a data member.
*/
template<class U>
Class<T>& addData(char const* name, U T::*mp, bool isWritable = true)
Class<T>& addData(char const* name, U T::* mp, bool isWritable = true)
{
assertStackState(); // Stack: const table (co), class table (cl), static table (st)

typedef const U T::*mp_t;
typedef const U T::* mp_t;
new (lua_newuserdata(L, sizeof(mp_t))) mp_t(mp); // Stack: co, cl, st, field ptr
lua_pushcclosure(L, &CFunc::getProperty<T, U>, 1); // Stack: co, cl, st, getter
lua_pushvalue(L, -1); // Stack: co, cl, st, getter, getter
Expand Down Expand Up @@ -1041,11 +1041,11 @@ class Namespace : public detail::Registrar
lua_newtable(L); // Stack: pns, ns, propset table (ps)
lua_rawsetp(L, -2, detail::getPropsetKey()); // ns [propsetKey] = ps. Stack: pns, ns

if (Security::hideMetatables())
{
lua_pushboolean(L, 0);
rawsetfield(L, -2, "__metatable");
}
if (Security::hideMetatables())
{
lua_pushboolean(L, 0);
rawsetfield(L, -2, "__metatable");
}

// pns [name] = ns
lua_pushvalue(L, -1); // Stack: pns, ns, ns
Expand Down
8 changes: 4 additions & 4 deletions Source/LuaBridge/detail/Stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <string>
#ifdef LUABRIDGE_CXX17
#include <string_view>
# include <string_view>
#endif

namespace luabridge {
Expand Down Expand Up @@ -50,7 +50,7 @@ struct Stack<lua_CFunction>

static lua_CFunction get(lua_State* L, int index) { return lua_tocfunction(L, index); }

static bool isInstance(lua_State* L, int index) { return lua_iscfunction(L, index); }
static bool isInstance(lua_State* L, int index) { return lua_iscfunction(L, index) != 0; }
};

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -82,7 +82,7 @@ struct Stack<int>
#else
int isNumber;
lua_tointegerx(L, index, &isNumber);
return isNumber;
return isNumber != 0;
#endif
}
};
Expand Down Expand Up @@ -295,7 +295,7 @@ struct Stack<bool>
{
static void push(lua_State* L, bool value) { lua_pushboolean(L, value ? 1 : 0); }

static bool get(lua_State* L, int index) { return lua_toboolean(L, index) ? true : false; }
static bool get(lua_State* L, int index) { return lua_toboolean(L, index) != 0; }

static bool isInstance(lua_State* L, int index) { return lua_isboolean(L, index); }
};
Expand Down
1 change: 0 additions & 1 deletion Source/LuaBridge/detail/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <LuaBridge/detail/Config.h>

#include <string>

namespace luabridge {

Expand Down
1 change: 0 additions & 1 deletion Source/LuaBridge/detail/dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "LuaBridge/detail/ClassInfo.h"

#include <iostream>
#include <string>

namespace luabridge {

Expand Down
Loading