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

Add Luau language #6612

Merged
merged 34 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7febf72
Feature: Add `Luau` language.
robloxiandemo Nov 11, 2023
912f57c
Featire: Add `Luau` code samples.
robloxiandemo Nov 11, 2023
81be622
Feature: Add the grammar.
robloxiandemo Nov 11, 2023
77339ab
Feature: Add `Luau` to grammar index.
robloxiandemo Nov 11, 2023
428f5d2
Fix: Add comment block and change the interpreter.
robloxiandemo Nov 11, 2023
1eced93
Feature: Add new samples in place of the old ones.
robloxiandemo Nov 12, 2023
c0dd82e
Patch: Slight typo in the header.
robloxiandemo Nov 12, 2023
a3a4286
Patch: Header typos again, I'm such a genius.
robloxiandemo Nov 12, 2023
ba342d6
Patch: Introduce the languageId.
robloxiandemo Nov 12, 2023
7463c5f
Patch: Resolve grammar conflict.
robloxiandemo Nov 12, 2023
f55cbc5
Patch: Resolve grammar conflict.
robloxiandemo Nov 12, 2023
b99f319
Patch: Update the hex value.
robloxiandemo Nov 14, 2023
92bed6f
Patch: Update the hex value.
robloxiandemo Nov 17, 2023
3ae7360
Sort
lildude Dec 6, 2023
5f21201
Patch: Update the submodule to the latest commit.
robloxiandemo Apr 3, 2024
405f7e4
Patch: Resolve merge conflicts.
robloxiandemo Apr 3, 2024
f0db075
Patch: Resolve further conflicts.
robloxiandemo Apr 3, 2024
3588fea
Patch: Remove conflict.
robloxiandemo Apr 4, 2024
f5eaf45
Patch: Reintroduce Luau into grammar index.
robloxiandemo Apr 4, 2024
1173698
Revert "Patch: Reintroduce Luau into grammar index."
robloxiandemo Apr 4, 2024
ec33c7d
Merge branch 'github-linguist:master' into master
robloxiandemo Apr 4, 2024
4d4b3eb
Patch: Retry resolving the conflict issue.
robloxiandemo Apr 4, 2024
afcdb27
Update vendor/licenses/git_submodule/Luau.tmLanguage.dep.yml
lildude Apr 5, 2024
d005379
Enhancement: Update old samples and their sources.
robloxiandemo Apr 5, 2024
2f9a8a2
Patch: Update old samples and their sources.
robloxiandemo Apr 6, 2024
6f5e853
Merge branch 'master' of https://github.com/robloxiandemo/linguist
robloxiandemo Apr 6, 2024
deb5f00
Patch: Update old samples and their sources.
robloxiandemo Apr 6, 2024
e3f8ba2
Merge branch 'master' of https://github.com/robloxiandemo/linguist
robloxiandemo Apr 6, 2024
f80ee08
Patch: Update old samples and their sources.
robloxiandemo Apr 6, 2024
0c0382a
Merge branch 'master' of https://github.com/robloxiandemo/linguist
robloxiandemo Apr 6, 2024
8fa4f1f
Patch: Update the samples further.
robloxiandemo Apr 6, 2024
481ae46
Revert "Patch: Update old samples and their sources."
robloxiandemo May 1, 2024
7bfe7ca
Test: New samples, sadly one source.
robloxiandemo May 1, 2024
b363c0c
Merge branch 'master' into master
lildude Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@
[submodule "vendor/grammars/lua.tmbundle"]
path = vendor/grammars/lua.tmbundle
url = https://github.com/textmate/lua.tmbundle
[submodule "vendor/grammars/luau.tmLanguage"]
path = vendor/grammars/luau.tmLanguage
url = https://github.com/JohnnyMorganz/Luau.tmLanguage.git
[submodule "vendor/grammars/m3"]
path = vendor/grammars/m3
url = https://github.com/newgrammars/m3
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ vendor/grammars/logtalk.tmbundle:
- source.logtalk
vendor/grammars/lua.tmbundle:
- source.lua
vendor/grammars/luau.tmLanguage:
- source.luau
vendor/grammars/m3:
- source.modula-3
vendor/grammars/make.tmbundle:
Expand Down
12 changes: 11 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# test changes in `test/test_blob.rb`.
#
# Please keep this list alphabetized. Capitalization comes before lowercase.
---
lildude marked this conversation as resolved.
Show resolved Hide resolved
1C Enterprise:
type: programming
color: "#814CCC"
Expand Down Expand Up @@ -3879,6 +3878,17 @@ Lua:
interpreters:
- lua
language_id: 213
Luau:
type: programming
tm_scope: source.luau
ace_mode: lua
codemirror_mode: lua
codemirror_mime_type: text/x-lua
color: "#14a5ff"
extensions:
- ".luau"
interpreters:
- lua
lildude marked this conversation as resolved.
Show resolved Hide resolved
lildude marked this conversation as resolved.
Show resolved Hide resolved
M:
type: programming
aliases:
Expand Down
37 changes: 37 additions & 0 deletions samples/Luau/signal.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--[[
Simple signal/slot implementation
]]
local signal_mt = {
__index = {
register = table.insert
}
}
function signal_mt.__index:emit(... --[[ Comment in params ]])
for _: number, slot: any in ipairs(self) do
slot(self, ...)
end
end
local function create_signal(): typeof(signal_mt)
return setmetatable({}, signal_mt)
end

-- Signal test
local signal: typeof(signal_mt) = create_signal()
signal:register(function(_signal, ...)
print(...)
end)
signal:emit('Answer to Life, the Universe, and Everything:', 42)

-- Output test
local testNumber: number = 10

print(`this is line, and "testNumber" equals to: {testNumber}.`)

--[==[ [=[ [[
Nested ]]
multi-line ]=]
comment ]==]
[==[ Nested
[=[ multi-line
[[ string
]] ]=] ]==]
170 changes: 170 additions & 0 deletions samples/Luau/vector.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
--// Vector
--// Written by Demo (R0BL0XIAN_D3M0)
--// [https://www.roblox.com/users/289025524/profile]
--// 11/09/2023

--// Types
type TVector = Vector2 | Vector3

--[=[
@class Vector

A collection of very useful vector-related functions.
]=]
local Vector = {}

--// Functions

--[=[
@within Vector

@param vector Vector2 -- The `Vector2` coordinate.

@return Vector3 -- Return the newly created `Vector3`.

Create a `Vector3` from a `Vector2` within the XY plane.
]=]
function Vector.FromVector2XY(vector: Vector2): Vector3
return (Vector3.new(vector.X, vector.Y, 0))
end

--[=[
@within Vector

@param vector Vector2 -- The `Vector2` coordinate.

@return Vector3 -- Return the newly created `Vector3`.

Create a `Vector3` from a `Vector2` within the XZ plane, unlike `FromVector2XY`.
]=]
function Vector.FromVector2XZ(vector: Vector2): Vector3
return (Vector3.new(vector.X, 0, vector.Y))
end

--[=[
@within Vector

@param vector Vector2 -- The initial `Vector2` coordinate.

@param _vector Vector2 -- The secondary `Vector2` coordinate.

@return number -- Return the computed angle in a numerical form or nil.

Compute the angle between two vectors in radians.
]=]
function Vector.RetrieveAngleRadian(vector: Vector2, _vector: Vector2): number?
if vector.Magnitude == 0 then
return nil
end

return (math.acos(vector:Dot(_vector)))
end

--[=[
@within Vector

@param vector Vector2 -- The initial `Vector2` coordinate.

@param _vector Vector2 -- The secondary `Vector2` coordinate.

@return number -- Return the computed angle in a numerical form.

Compute the angle between two vectors.
]=]
function Vector.AngleBetweenVectors(vector: Vector2, _vector: Vector2): number
local newVector: Vector2 = (_vector.Magnitude * vector)
local _newVector: Vector2 = (vector.Magnitude * _vector)

return (2 * (math.atan2((_newVector - newVector).Magnitude, (newVector + _newVector).Magnitude)))
end

--[=[
@within Vector

@param vector Vector3 -- The original `Vector3` coordinate.

@param amount number -- The primary amount.

@return Vector3 -- Return the rounded `Vector3`.

Round the specified `Vector3` to the nearest number.
]=]
function Vector.Round(vector: Vector3, amount: number): Vector3
return (
Vector3.new(
((math.round(vector.X / amount)) * amount),
((math.round(vector.Y / amount)) * amount),
((math.round(vector.Z / amount)) * amount)
)
)
end

--[=[
@within Vector

@param vector TVector -- The vector coordinate (`Vector2` or `Vector3`).

@param maxMagnitude number -- The maximum magnitude.

@return number -- Return the clamped magnitude.

Clamp the magnitude of a vector so it is only a certain length.
]=]
function Vector.ClampMagnitude(vector: TVector, maxMagnitude: number): number
return ((vector.Magnitude > maxMagnitude) and (vector.Unit * maxMagnitude) or vector)
end

--[=[
@within Vector

@param vector TVector -- The initial vector coordinate (`Vector2` or `Vector3`).

@param _vector TVector -- The secondary vector coordinate (`Vector2` or `Vector3`).

@return number -- Return the radianed angle.

Finds the angle in radians between two vectors.
]=]
function Vector.AngleBetween(vector: TVector, _vector: TVector): number
return (math.acos(math.clamp(vector.Unit:Dot(_vector.Unit), -1, 1)))
end

--[=[
@within Vector

@param vector TVector -- The initial vector coordinate (`Vector2` or `Vector3`).

@param _vector TVector -- The secondary vector coordinate (`Vector2` or `Vector3`).

@param axisVector Vector -- The axis vector coordinate (`Vector` or `Vector3`).

@return number -- Return the radianed angle.

Finds the angle in radians between two vectors and returns a signed value.
]=]
function Vector.AngleBetweenSigned(vector: TVector, _vector: TVector, axisVector: TVector): number
local angle: number = Vector.AngleBetween(vector, _vector)

return (angle * (math.sign(axisVector:Dot(vector:Cross(_vector)))))
end

--[=[
@within Vector

@return Vector3 -- Return the random `Vector3` coordinate.

Return a random unit vector (could be used for equal distribution around a sphere).
]=]
function Vector.RetrieveRandomUnitVector(): Vector3
local randomX: number = (2 * ((math.random()) - 0.5))
local randomY: number = (6.2831853071796 * (math.random()))
local randomZ: number = ((1 - (randomX * randomX)) ^ 0.5)

local X: number = randomX
local Y: number = (randomZ * (math.cos(randomZ)))
local Z: number = (randomZ * (math.sin(randomY)))

return (Vector3.new(X, Y, Z))
end

return Vector
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **LookML:** [atom/language-yaml](https://github.com/atom/language-yaml)
- **LoomScript:** [ambethia/Sublime-Loom](https://github.com/ambethia/Sublime-Loom)
- **Lua:** [textmate/lua.tmbundle](https://github.com/textmate/lua.tmbundle)
- **Luau:** [JohnnyMorganz/Luau.tmLanguage](https://github.com/JohnnyMorganz/Luau.tmLanguage)
- **M4:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc)
- **M4Sugar:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc)
- **MATLAB:** [mathworks/MATLAB-Language-grammar](https://github.com/mathworks/MATLAB-Language-grammar)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/luau.tmLanguage
Submodule luau.tmLanguage added at 9f320a
56 changes: 56 additions & 0 deletions vendor/licenses/git_submodule/luau.tmLanguage.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Luau.tmLanguag
version: 9f320add6dd099f99897a03c5e2ce3ca5f176d7f
type: git_submodule
homepage: https://github.com/JohnnyMorganz/Luau.tmLanguage.git
license: mit
licenses:
- sources: LICENSE.md
text: |-
Copyright (c) JohnnyMorganz
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

===

Copyright (c) Microsoft Corporation
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
notices: []