So, I was just looking at random things in the script editor, when I saw the export
keyword. I wanted to see what it does, but had no idea how to use it. To learn, I checked everywhere, but I couldn’t find a single source. Does anyone know what it does and how to use it? I am looking forward to learning about this.
1 Like
It just allows you to export a type from a module script to be accessible from another script.
Module:
local module = {}
export type vector = {x: number; y: number}
return module -- since you have to return something for require not to fail
Script:
local a: vector = {x = 1; y = 1} -- unknown type 'vector'
local a: module.vector = {x = 1; y = 1} -- unknown type 'module.vector'
local module = require(path.to.module) -- requiring also imports the exported types from the module
local a: module.vector = {x = 1; y = 1} -- now ok
It’s more thoroughly documented on the luau language site:
^Also note that it for reverse compatibility reasons (luau is a language that actively goes through syntax changes), export
is not a reserved word (like the continue statement).
So the following is valid syntax that will run without any syntax errors:
local export = 'a'
local a = export
6 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.