-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(citizen-scripting-lua): table.size function #3093
base: master
Are you sure you want to change the base?
Conversation
Any benchmark to compare the performance of using this instead of doing the size in Lua ? |
Is there really a reason to add this vs the user having their own extension functions (similar to how gmod does it) |
I did a benchmark and c++ version is faster than Lua.
I would say it can help developers so they don't have to write these functions in every script they make. I know that frameworks such as ESX provide functions like this but people who makes standalone scripts or "multi-framework" have to make their own. It will simply make their work a little easier/faster. |
May I ask what the table size was used for those results ? |
Isn't the recommended way to store the size inside a extra value in lua? Then you do not traverse the table to calculate it. |
function table.size(tbl)
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
return count
end I think there won't be any huge difference with
I have tried one thing but i had a problem with implementing it. I only found a way to do this but it's inside lua source code, so I would have to make pr there. If u have some idea how to make it, show/describe it. |
My main concern here is that people will constantly want more and more functions added for convenience which adds more possible breakage points for Cfx if there's ever another Lua version upgrade. |
It just seems so unnecessary. It's not hard to implement in your own resource or load from an external resource.
I would assume he meant how large was the table being tested, rather than what was the Lua function. |
So their functions will simply be assessed in terms of usefulness as this one.
Of course it's not hard but implementing it for the x time is frustrating.
10.000.000 |
Goal of this PR
Add table.size function to lua runtime so developers can use it to get size of tables. Mostly useful for hex tables because # will always return 0.
How is this PR achieving the goal
By declaring Lua_TableSize function and setting it in global table.
This PR applies to the following area(s)
ScRT: Lua
Successfully tested on
Game builds: ..
Platforms: Linux
Checklist