#Include in Luau

I hate how module scripts are horrible for performance and hard to manage, but there were no other solutions to organize the game, really.
My solution: duct taping everything and making a plugin to sync up code fields, heavily inspired by header files from C/C++
I will make this plugin free and open soon; it’s almost completed.



image

Edit: Plugin is done:

9 Likes

I love stuff like this.

How does it work? I can’t figure out what you mean by code fields lol

2 Likes

I love this so so so so so so soooo much, you have made me so happy by creating this.

2 Likes

what an amazing idea

next, implement #define

#define true false
1 Like
#include <stdio.h>

#define WOW int
#define SUCH main
#define GOOD (
#define SCRIPTING )
#define MUCH {
#define GREAT printf
#define OK ("1337")
#define THANKS ;
#define BYE return 0; }

WOW SUCH GOOD SCRIPTING MUCH GREAT OK THANKS BYE
3 Likes

It looks cool, but I do have a few questions, especially in the nature of how this is implemented, mostly because it is labelled #include.

  1. Does this literally just copy and paste the include contents into the file that included it?
  2. Does this avoid redefinition issues? for example, if you had two “headers” that both defined functions under the same signature, would it error out for duplicate definitions or just use the one from the latest header you included? It could cause a fair amount of issues and subtle bugs if not.
  3. (similar to 2) Do you plan to add support for include rules like #pragma once or legacy include guards?
  4. The main upside to modules is providing quick and easy access to shared data between scripts. Does this have a kind of alternative (or a wrapper with modules) or is this omitted entirely?
  5. This would definitely pollute the global scope; do you plan to add some kind of namespacing system?
  6. Can you declare things private to the “header” file, similar to the static keyword?
  7. Why this over require with a module?
  8. Is this part of a larger preprocessor?

My main concern is the fact that #include is designed for a compiled language with translation units, and, well, Luau isn’t compiled (the same way that C/C++ is), and it (obviously, given the previous statement) doesn’t have translation units.

2 Likes

It’s either satire or Yarik is going to implement a C interpreter. Not transpiler, interpreter. Clearly, he is going to rewrite the script editor and add an LSP for C.

3 Likes

i cant wait for an unsafe language to become interpreted

1 Like

He is going to implement pointers by treating C like a brainfuck interpreter and making a very big array for memory

4 Likes

RAM inside RAM?! revolutionary!! :exploding_head:

maybe then he’ll port open source Luau to the interpreted C/C++ so we have a true luau inside luau

2 Likes

Luauception. In his C in Luau there will be a Luau implementation, implemented in C in Luau. Then in that Luau he will implement C again. And then in that C he will implement Luau. This pattern repeats until he dies of old age.

2 Likes

no itll stack overflow first because of deep recursion
if you could even call it recursion in this context…

breaking news, yarik somehow manages to get a segfault in luau (he implemented C and his code somehow became unsafe)

2 Likes

More seriously, can you rate my plugin out of 10?!?!?!? :speaking_head::fire:

local ScriptEditorService = game:GetService("ScriptEditorService")

ScriptEditorService.TextDocumentDidOpen:Connect(function(doc)
	doc:CloseAsync()
end)
3 Likes

yes but its not a real segfault (or access violation if you’re on windows :nerd_face:) :c

10/10 plugin it forces scripters to touch grass

1 Like

A well known issue with include is that it copies each header file multiple times, while I know things like pragma once are designed to fix this issue in C++, how has this been handled here?

1 Like

yarik is going to pull the

#ifndef FILENAME_H
#define FILENAME_H
// Header file contents
#endif

basically updates scripts that have this header
Uses auto completion callback aswell to make editing easier
https://create.roblox.com/docs/reference/engine/classes/ScriptEditorService#RegisterAutocompleteCallback

Uh its just a regex pasting code snippets and updating them
Not a real AST

Yeah I know I was partaking in a little game of “Humor,” a very sophisticated aristocratic game played only by Roblox’s most intelligent minds

2 Likes