mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
Backport the WoW global strsplit(sep, str [, pieces]) to 1.12, ported from 3.3.5's strsplit (FUN_00816a60): split str on any character in sep, returning the pieces as multiple values; pieces>0 caps the count with the unsplit remainder as the final piece (0/omitted = unlimited, 1 = whole string). Consecutive/trailing delimiters yield empty pieces, matching retail. Two deliberate changes from the 3.3.5 source: - Skip its lua_settop(L, 0). Popping the args un-roots the source string, so a GC step during a pushlstring could free the buffer we're still scanning. Leaving the args on the stack keeps the source GC-rooted; Lua returns the top N (the pieces) regardless of the args below. - Bind lua_checkstack (0x006F2F30, __fastcall(L, size) -> int, found via its cmp ...,0x800 LUA_MAXCSTACK test) as Game::Lua::CheckStack and guard every push with it, erroring "strsplit(): Stack overflow" like 3.3.5 on genuine exhaustion (strsplit pushes an unbounded number of results). Reusable for any future multi-return C function. Registered on both Lua states. Verified in-game across basic split, pieces cap, multi-char separator set, empty middle piece, and empty-separator cases.