ID:2945809
 
Applies to:ByondAPI
Status: Open

Issue hasn't been assigned a status value.
It would be nice if we could work with both the file() proc and files included via 'resource.dmm' directly in ByondAPI.

The main usage I have for this is my maploader, where I'd like to be able to support all three of these methods for calling it:
call_ext("bapidmm", "byond:load_map")('map.dmm')
call_ext("bapidmm", "byond:load_map")(file("map.dmm"))
call_ext("bapidmm", "byond:load_map")("map.dmm")


For my use-case, a way to read the file to a string would work, but an arbitrary buffer is probably more generally useful for file types other than text?

On the C/Rust side, this could look like
extern "C" BYOND_EXPORT CByondValue load_map(int n, CByondValue v[]) {
char* result;
int length = Byond_ReadFileToString(v[0], &result);
}

or perhaps
extern "C" BYOND_EXPORT CByondValue load_map(int n, CByondValue v[]) {
void* result;
int length = Byond_ReadFile(v[0], &result);
}


A way to query what you're given as an argument would also be helpful:
extern "C" BYOND_EXPORT CByondValue load_map(int n, CByondValue v[]) {
if (Byond_IsFile(v[0])) {
// can safely call Byond_ReadFile and Byond_ReadFileToString, this could be a file() or 'file'
}
if (Byond_IsFileInRsc(v[0])) {
// specifically checking if it's 'file.dmm' but NOT file("file.dmm")? not sure if the difference matters
}
}


Also useful would be a way to turn a file into a path string just for debugging.
extern "C" BYOND_EXPORT CByondValue load_map(int n, CByondValue v[]) {
if (Byond_IsFile(v[0])) {
char* filePath;
int length = Byond_FilePath(v[0], &filePath);
}
}


I'm far from set on these being the exact APIs, this is borderline psuedocode to give ideas.