Skip to content
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

Merged
merged 6 commits into from
May 27, 2024

Conversation

ranisalt
Copy link
Member

@ranisalt ranisalt commented May 8, 2024

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 the tfs::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.

src/luascript.h Fixed Show fixed Hide fixed
@ranisalt ranisalt marked this pull request as ready for review May 10, 2024 21:51
@EvilHero90 EvilHero90 added this to the 1.8 milestone May 14, 2024
@@ -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()) {
Copy link
Contributor

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

Copy link
Member Author

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::

Copy link
Contributor

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

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

A stack address which arrived via a [parameter](1) may be assigned to a non-local variable.
@ranisalt ranisalt modified the milestones: 1.8, 1.6 May 26, 2024
@ranisalt ranisalt mentioned this pull request May 26, 2024
3 tasks
DSpeichert
DSpeichert previously approved these changes May 26, 2024
@ranisalt ranisalt merged commit 55c0462 into otland:master May 27, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants