How to iterate over directory contents in Squirrel-lang?

38 views Asked by At

I need to use Squirrel-lang for a college assignment, and I have to count the files in a directory tree using threads. I've got the treading under control, but I can't for the life of me find any useful information on how to navigate directories in this language. So far I've only managed to figure out that I can open a directory as a file (Which makes sense in an UNIX system) using

local currDirr = file(".", "r");

But the Squirrel documentation is incredibly vague regarding its filesystem API and any similar questions I could find on the matter are 10+yrs old, when Squirrel didn't even have an IO library yet. Does anyone know how I could traverse the filesystem here? Or at least point me in a direction to embed some C/C++ code that lets me do this through Squirrel's C API.

Thanks in advance

PD: Just in case anyone wonders why I have to use Squirrel specifically, the assignment is to solve 2 threading-related problems with a language whose name has the same number of letters as yours. Squirrel was the closest thing I could find to a general purpose language with 8 letters that had more than 5 sentences written about it online. If anyone knows of another language that would be better suited for this, said suggestions are also welcome.

1

There are 1 answers

0
Vulc4n On

I hope this is not too late. You can check the minimal implementation of the language in the official repository. On top of it, you can register your own functions in the root table. The docs provide an example:

SQInteger register_global_func(HSQUIRRELVM v, SQFUNCTION f, const char* fname)
{
    sq_pushroottable(v);
    sq_pushstring(v, fname, -1);
    sq_newclosure(v, f, 0); //create a new function
    sq_newslot(v, -3, SQFalse);
    sq_pop(v, 1); //pops the root table
    return 0;
}

register_global_func(v, myfunc, _SC("myfunc"));

So you can register a function like the ones suggested in this question.