Fix substring bug in require() (#867)
Some checks failed
Build coop / build-linux (push) Has been cancelled
Build coop / build-steamos (push) Has been cancelled
Build coop / build-windows-opengl (push) Has been cancelled
Build coop / build-windows-directx (push) Has been cancelled
Build coop / build-macos-arm (push) Has been cancelled
Build coop / build-macos-intel (push) Has been cancelled

* Fix substring bug in require()

When require() was searching for a matching module, it would only
consider the end of the filename. So foobar.lua and bar.lua could both
match a require('bar').

This commit fixes that.

* remove debug logs

---------

Co-authored-by: MysterD <myster@d>
This commit is contained in:
djoslin0 2025-06-22 03:48:42 -07:00 committed by GitHub
parent c68ee859ea
commit 06e9c8aa2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,10 +38,12 @@ static struct ModFile* smlua_find_mod_file(const char* moduleName) {
int bestTotalDepth = INT_MAX;
bool foundRelativeFile = false;
char rawName[SYS_MAX_PATH] = "";
char luaName[SYS_MAX_PATH] = "";
char luacName[SYS_MAX_PATH] = "";
snprintf(luaName, SYS_MAX_PATH, "%s.lua", moduleName);
snprintf(luacName, SYS_MAX_PATH, "%s.luac", moduleName);
snprintf(rawName, SYS_MAX_PATH, "/%s", moduleName);
snprintf(luaName, SYS_MAX_PATH, "/%s.lua", moduleName);
snprintf(luacName, SYS_MAX_PATH, "/%s.luac", moduleName);
for (int i = 0; i < gLuaActiveMod->fileCount; i++) {
struct ModFile* file = &gLuaActiveMod->files[i];
@ -57,7 +59,7 @@ static struct ModFile* smlua_find_mod_file(const char* moduleName) {
}
// check for match
if (!str_ends_with(file->relativePath, moduleName) && !str_ends_with(file->relativePath, luaName) && !str_ends_with(file->relativePath, luacName)) {
if (!str_ends_with(file->relativePath, rawName) && !str_ends_with(file->relativePath, luaName) && !str_ends_with(file->relativePath, luacName)) {
continue;
}