-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move static LuaScriptInterface methods to namespace #4675
Conversation
540530d
to
79ff9ca
Compare
@@ -505,20 +505,20 @@ int32_t Weapon::getHealthCost(const Player* player) const | |||
bool Weapon::executeUseWeapon(Player* player, const LuaVariant& var) const | |||
{ | |||
// onUseWeapon(player, var) | |||
if (!scriptInterface->reserveScriptEnv()) { | |||
if (!tfs::lua::reserveScriptEnv()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason for naming it tfs::lua
instead of simply lua
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramon-bernardo avoiding possible clashes with other libs. If at some point we use a dependency that defines a namespace lua
(say a C++ wrapper for Lua) then it may clash with our functions.
This happened with OpenSSL already (it defines a global RSA
struct). Ideally, we will wrap the entire code in namespace tfs
so we can drop tfs::
and it will be just lua::
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranisalt thanks for clarifying, that's what I imagined. We could do a lot like tfs::x
, right?
I've been looking at game events, I thought something like...
tfs::game::events::x
tfs::game::map::tows::x
79ff9ca
to
25a7a8e
Compare
void pushUserdata(lua_State* L, T* value) | ||
{ | ||
T** userdata = static_cast<T**>(lua_newuserdata(L, sizeof(T*))); | ||
*userdata = value; |
Check warning
Code scanning / CodeQL
Local variable address stored in non-local memory
b8f5fb4
to
b0c753c
Compare
Pull Request Prelude
Changes Proposed
Part 1 of a major rewrite to our dearest file that hangs low-powered computers and triggers out-of-memory situations all the time.
At first, move static functions (except functions that will be bound to Lua methods) out of the
LuaScriptInterface
class into thetfs::lua
namespace. This should help reducing the load to compile this file and enables cleaning up the header in the future.A few unused functions were removed, and some that weren't used outside
luascript.cpp
were moved into it as static, within an anonymous namespace.