Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to not use require / consider the whole project #887

Open
SyBozzDEV opened this issue Jan 1, 2025 · 2 comments
Open

Option to not use require / consider the whole project #887

SyBozzDEV opened this issue Jan 1, 2025 · 2 comments

Comments

@SyBozzDEV
Copy link

A few days ago I figured out that Farming Simulator 25 is using luau and not lua, thought it seems it's nowhere mentioned.
I just saw _G._VERSION = "Luau" and some testing confirmed it.

So I tried setting up an project to use the features of Luau in vscode/vscodium but since Giants (FS25 Developer) modified the implementation they don't have a require function.

They provide two ways to include a file in a mod, either through their modDesc.xml file or with the global function source(filePath).
Though source() can not be seen as a require replacement, since it doesn't return anything from the file but loads it.

I setup a little minimal project to showcase this but also for testing the difinition of the FS25 api.
https://github.com/SyBozzDEV/FS25_luau_test-setup

The enhancement / request I would like to suggest is an option to disable require and allow the lsp to consider all luau / lua files, maybe by setting the files to consider e.g. src/. I think that way would allow a more general usage since adding the specific LS25 functionality seems a bit much.

Though maybe there are already ways to achieve this with some settings or tricks I didn't find.
I did find the trick where I could setup a type definition for the project but that would mean to always write double the amount and have to deal with the BuiltinGlobalWrite message.

@JohnnyMorganz
Copy link
Owner

Very interesting to hear that Farming Simulator uses Luau!

Switching away from considering require and instead using the whole source tree might be a bit challenging. The way the Luau analysis library is built revolves around tying files together using require syntax, so I would need to see how we could get around that.

How do files reference other files then - I'm guessing functions and variables just end up getting loaded into the global namespace, and can reference each other depending on their ordering in the XML file?

You might find quicker success here by using requires normally and then creating a quick post processing tool to remove the require lines

@SyBozzDEV
Copy link
Author

SyBozzDEV commented Jan 1, 2025

Oh that sounds like an interesting trick, it would involve adding a require and return at the end of the file but could work.

And each mod has their own environment so to speak but through getmetatable(_G).__index you could access the true global namespace. So yes each file gets loaded into the global mod namespace, except that local is honored, I guess you could see each file as a block. Everything global in there gets loaded into the global mod namespace.

But a suggestion would be adding a comment/option with an luau lsp option, e.g. ---@require file1, file2 so it could still use the file order structure which is needed I assume, and if it's allowed to be placed at different positions and not just at the top it might be a possible option. Though in FS25 we don't add a return at the end of the file, since all the content gets loaded, so I'm not sure how that would affect this idea.

And yes the order is determined by the order in the xml, or if the source() function is called. (Example is in my little test setup repo with comments.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants