I’ve raised this question in the general chat but I think here would be a better place for questions that could be repeated in future:
IDK if this is avaialble already, but suppose my directory is {space_root}/.spacelua/init.lua. Can I use dofile(".spacelua") directly or should I use dotfile(".spacelua/init.lua")?
Secondly, what is the executing directory of our spacelua functions? Are they executed in the spaceroot or in their own directories in which file they are invoked? This should be relevant for dofile usage which needs to be related to a directory.
As I looked at it I realized this will have broken quite a while ago (it used read_file before which no longer exists). I just pushed an (untested — sorry) fix, which should help.
What it does is simply load the path name from the root of your space. So dofile("spacelua/init.lua") will load that file. There’s no magic handling of init.lua files. Also I fear putting things in a .dotfolder will not work because I don’t think SB syncs hidden folders. _spacelua/init.lua should work though.
In principle Lua also has a require function, which Space Lua hasn’t implemented yet. I’m not sure if it should. I kind of like the idea of having all scripts in space-lua blocks so you can edit them in SB itself. However, if there’s a strong desire for people to edit .lua files maybe the infrastructure for this can be improved.
I personally really want the require and editing inside a proper code editor (not note editor) so that we will have a properly modularization to implement plugins. That depends on how you envision the growth of Silverbullet.
I think with the introduction of space lua, SB could evolve in a direction like neovim, which the core project barely implement any fancy stuff (looks decades old when out of box) but a solid code base with extensible apis, while most of the upper structure can be alleviated to other contributors who might not have web background (like me). I think the convenience of space lua is unprecedented. It will definitely allow more people to contribute to this project and the sky is the limit! So I personally think this is the right direction to go.
With that vision in mind, allowing lua file would not limit people to just write a few util functions rather some more complicated projects. I’m playing a lot these two days with space lua and TBH it is not as convenient to debug. SilverBullet has already great completion (on the standard of a note editor) and possibility to easily print out debug strings but it won’t hint me when I misused some variables with typo.
Aside from the inconvenience of editing, the distribution of those code can also be a problem in the future. Right now with lua in the markdown file I’ll be interested only to show a snippet in the forum, barely it will be updated in the future. But with a project it would be super convenient to distribute a proper codebase that will enable larger scale of collaboration.