// creating the object
// lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it
// and that's what we do with placement-new
+ static_assert(alignof(TType) <= 8);
const auto pointerLocation = static_cast<TType*>(lua_newuserdata(state, sizeof(TType)));
new (pointerLocation) TType(std::forward<TType2>(value));
}
// creating the object
// lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it
// and that's what we do with placement-new
+ // static_assert(alignof(TFunctionObject) <= 8); XXX trips on at least c++lib 17, see #13766
const auto functionLocation = static_cast<TFunctionObject*>(lua_newuserdata(state, sizeof(TFunctionObject)));
new (functionLocation) TFunctionObject(std::move(fn));
};
// we copy the function object onto the stack
+ static_assert(alignof(TFunctionObject) <= 8);
const auto functionObjectLocation = static_cast<TFunctionObject*>(lua_newuserdata(state, sizeof(TFunctionObject)));
new (functionObjectLocation) TFunctionObject(std::move(fn));
luaCtx.registerFunction("toString", &ServerPolicy::toString);
luaCtx.registerFunction("__tostring", &ServerPolicy::toString);
- ServerPolicy policies[] = {
+ static const std::array<ServerPolicy, 6> policies = {
ServerPolicy{"firstAvailable", firstAvailable, false},
ServerPolicy{"roundrobin", roundrobin, false},
ServerPolicy{"wrandom", wrandom, false},
ServerPolicy{"chashed", chashed, false},
ServerPolicy{"leastOutstanding", leastOutstanding, false}
};
- for (auto& policy : policies) {
- luaCtx.writeVariable(policy.d_name, policy);
+ for (const auto& policy : policies) {
+ luaCtx.writeVariable(policy.d_name, &policy);
}
#endif /* DISABLE_POLICIES_BINDINGS */