-
Notifications
You must be signed in to change notification settings - Fork 6
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
Adjust implementation of table functions #98
Conversation
a84d1f5
to
288ef89
Compare
I've done a few AI vs AI games and they appear to run fine. I'll do a few manual tests next. |
bda1223
to
1c57c00
Compare
Made it compatible with Python patcher |
section/Lua/TableFuncs.cpp
Outdated
|
||
const luaL_reg RegTableFuncsDesc[] = {{"getsize2", &lua_tablesize}, | ||
{"empty2", &lua_tableempty}, | ||
{"getn2", (lua_CFunction)0x00927C20}, |
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.
Do we still need these 2
alternatives?
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.
I can remove them.
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.
The problem is Lua resets them in current dev branch:
--- table.empty(t) returns true iff t has no keys/values.
---@param t table
---@return boolean
function table.empty(t)
if type(t) ~= 'table' then return true end
return next(t) == nil
end
--- Returns actual size of a table, including string keys
---@param t table
---@return number
function table.getsize(t)
if type(t) ~= 'table' then return 0 end
local size = 0
for k, v in t do
size = size + 1
end
return size
end
-- replace with assembly implementations
table.empty = table.empty2 or table.empty
table.getsize = table.getsize2 or table.getsize
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.
Then we remove that logic. As long as the assembly versions are functionally equivalent then that should be no issue.
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.
See also: FAForever/fa#6537
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.
Done
If we want to have deepcopy here is how it was done in my dev branch https://github.com/4z0t/FA-Binary-Patches/blob/develop/section/Lua/LuaObject.cxx#L87-L121 |
table.getsize
used to return 0 when given non table value. Make asm implementation do the same as well. related to Always return a number fromtable.getn
andtable.getsize
#97;table.getsize
in C++;table.empty
in C++.