Skip to content

Commit 5778863

Browse files
authored
Merge branch 'primary' into update-lute
2 parents 625a59f + 2326c7f commit 5778863

File tree

19 files changed

+339
-114
lines changed

19 files changed

+339
-114
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
__pycache__
1414
.cache
1515
.clangd
16+
**/.DS_Store
1617
compile_commands.json
1718
*~
1819
extern/*/

.lute/luthier.luau

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--!strict
2+
3+
local process = require("@lute/process")
4+
5+
local args = table.pack(...)
6+
7+
local cmd = { process.execpath(), "tools/luthier.luau", table.unpack(args, 2, args.n) }
8+
9+
local result = process.run(cmd, { stdio = "inherit" })
10+
process.exit(result.exitcode)

examples/serve_html.luau

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
local net = require("@std/net")
1+
local net = require("@lute/net")
22

33
local server = net.serve({
44
port = 8080,
5-
handler = function(req: net.receivedrequest): net.serverresponse
5+
handler = function(req: net.ReceivedRequest): net.ServerResponse
66
local headers = ""
77
for key, value in req.headers do
88
headers ..= `\n {key}: {value}`

extern/luau.tune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[dependency]
22
name = "luau"
33
remote = "https://github.com/luau-lang/luau.git"
4-
branch = "0.702"
5-
revision = "c836feb2450a074581010f84da2eadeea38a3d55"
4+
branch = "0.703"
5+
revision = "c33adf13ed76302c293c442ab13fc84874c53ea5"

lute/cli/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ target_sources(Lute.CLI.lib PRIVATE
4747

4848
target_compile_features(Lute.CLI.lib PUBLIC cxx_std_17)
4949
target_include_directories(Lute.CLI.lib PUBLIC include ${CLI_GENERATED_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
50-
target_link_libraries(Lute.CLI.lib PRIVATE Luau.Common Luau.Compiler Luau.Config Luau.CodeGen Luau.Analysis Luau.VM Lute.CLI.Commands Lute.Crypto Lute.Fs Lute.IO Lute.Luau Lute.Net Lute.Task Lute.VM Lute.Process Lute.System Lute.Time Lute.Require Lute.Runtime Luau.CLI.lib zlibstatic)
50+
target_link_libraries(Lute.CLI.lib PRIVATE Luau.Common Luau.Compiler Luau.Config Luau.CodeGen Luau.Analysis Luau.VM Lute.CLI.Commands Lute.Luau Lute.Process Lute.Require Lute.Runtime Luau.CLI.lib zlibstatic)
5151
target_compile_options(Lute.CLI.lib PRIVATE ${LUTE_OPTIONS})
5252

5353
add_executable(Lute.CLI)

lute/cli/src/climain.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ static const char* HELP_STRING = R"(Usage: lute <command> [options] [arguments..
3939
check Type check Luau files.
4040
compile Compile a Luau script into a standalone executable.
4141
setup Generate type definition files for the language server.
42-
transform Run a specified code transformation on specified Luau files.
43-
lint Run linting rules on specified Luau files.
42+
transform Run a specified code transformation on specified Luau files.
43+
lint Run linting rules on specified Luau files.
4444
4545
Run Options (when using 'run' or no command):
4646
lute [run] <script.luau> [args...]
@@ -57,20 +57,20 @@ Compile Options:
5757
Setup Options:
5858
lute setup
5959
Generates type definition files for the language server.
60-
--with-luaurc Defines aliases to the type definition files in the working directory's luaurc file.
60+
--with-luaurc Defines aliases to the type definition files in the working directory's luaurc file.
6161
6262
Transform Options:
63-
lute transform <transformer script> [options...] <files...>
64-
Runs the specified code transformation on the provided Luau files.
65-
--dry-run Runs the transformation without actually overwriting or deleting any files.
66-
--output <path> Specifies an output file for a transformed file. Only valid when
67-
transforming a single file. If not specified, files are overwritten in place.
63+
lute transform <transformer script> [options...] <files...>
64+
Runs the specified code transformation on the provided Luau files.
65+
--dry-run Runs the transformation without actually overwriting or deleting any files.
66+
--output <path> Specifies an output file for a transformed file. Only valid when
67+
transforming a single file. If not specified, files are overwritten in place.
6868
6969
Lint Options:
70-
lute lint [options...] <paths...>
71-
Runs linting rules on the specified Luau files.
72-
--rules <path> Path to a single lint rule or a directory containing multiple lint rules.
73-
If not specified, default lint rules are used.
70+
lute lint [options...] <paths...>
71+
Runs linting rules on the specified Luau files.
72+
--rules <path> Path to a single lint rule or a directory containing multiple lint rules.
73+
If not specified, default lint rules are used.
7474
7575
General Options:
7676
-h, --help Display this usage message.
@@ -244,19 +244,23 @@ static std::pair<bool, std::string> getValidPath(std::string filePath)
244244
if (filePath.find('.') != std::string::npos)
245245
return {false, res};
246246

247-
std::string fallbackPath = joinPaths(".lute", filePath);
248-
size_t fallbackSize = fallbackPath.size();
247+
const std::array<std::string, 4> fallbackPaths = {
248+
joinPaths(".lute", filePath + ".lua"),
249+
joinPaths(".lute", filePath + ".luau"),
250+
joinPaths(joinPaths(".lute", filePath), "init.lua"),
251+
joinPaths(joinPaths(".lute", filePath), "init.luau"),
252+
};
249253

250-
for (const auto& ext : {".luau", ".lua"})
254+
for (std::optional<std::string> currentPath = getCurrentWorkingDirectory(); currentPath; currentPath = getParentPath(*currentPath))
251255
{
252-
fallbackPath.resize(fallbackSize);
253-
fallbackPath += ext;
254-
255-
if (isFile(fallbackPath))
256-
return {true, fallbackPath};
256+
for (const std::string& fallbackPath : fallbackPaths)
257+
{
258+
const std::string commandPath = joinPaths(*currentPath, fallbackPath);
259+
if (isFile(commandPath))
260+
return {true, commandPath};
261+
}
257262
}
258263

259-
260264
return {false, res};
261265
}
262266

lute/cli/src/requiresetup.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,21 @@
22

33
#include "lute/bundlevfs.h"
44
#include "lute/clivfs.h"
5-
#include "lute/crypto.h"
6-
#include "lute/fs.h"
7-
#include "lute/io.h"
8-
#include "lute/luau.h"
9-
#include "lute/net.h"
105
#include "lute/packagerequirevfs.h"
11-
#include "lute/process.h"
126
#include "lute/require.h"
137
#include "lute/requirevfs.h"
148
#include "lute/runtime.h"
15-
#include "lute/system.h"
16-
#include "lute/task.h"
17-
#include "lute/time.h"
189
#include "lute/userlandvfs.h"
19-
#include "lute/vm.h"
2010

2111
#include "Luau/CodeGen.h"
2212
#include "Luau/Require.h"
2313

14+
#include "lualib.h"
15+
2416
#include <memory>
2517
#include <string>
2618
#include <utility>
2719

28-
static void luteopen_libs(lua_State* L)
29-
{
30-
std::vector<std::pair<const char*, lua_CFunction>> libs = {{
31-
{"@lute/crypto", luteopen_crypto},
32-
{"@lute/fs", luteopen_fs},
33-
{"@lute/luau", luteopen_luau},
34-
{"@lute/net", luteopen_net},
35-
{"@lute/process", luteopen_process},
36-
{"@lute/task", luteopen_task},
37-
{"@lute/vm", luteopen_vm},
38-
{"@lute/system", luteopen_system},
39-
{"@lute/time", luteopen_time},
40-
{"@lute/io", luteopen_io},
41-
}};
42-
43-
for (const auto& [name, func] : libs)
44-
{
45-
lua_pushcfunction(L, luarequire_registermodule, nullptr);
46-
lua_pushstring(L, name);
47-
func(L);
48-
lua_call(L, 2, 0);
49-
}
50-
}
51-
5220
static void* createCliRequireContext(lua_State* L)
5321
{
5422
void* ctx = lua_newuserdatadtor(
@@ -138,8 +106,6 @@ lua_State* setupCliState(Runtime& runtime, std::function<void(lua_State*)> preSa
138106
runtime,
139107
[preSandboxInit = std::move(preSandboxInit)](lua_State* L)
140108
{
141-
luteopen_libs(L);
142-
143109
if (Luau::CodeGen::isSupported())
144110
Luau::CodeGen::create(L);
145111

@@ -160,8 +126,6 @@ lua_State* setupPkgCliState(
160126
runtime,
161127
[directDependencies = std::move(directDependencies), allDependencies = std::move(allDependencies)](lua_State* L)
162128
{
163-
luteopen_libs(L);
164-
165129
if (Luau::CodeGen::isSupported())
166130
Luau::CodeGen::create(L);
167131

@@ -180,7 +144,6 @@ lua_State* setupBundleState(
180144
runtime,
181145
[luaurcFiles = std::move(luaurcFiles), bundleMap = std::move(bundleMap)](lua_State* L)
182146
{
183-
luteopen_libs(L);
184147
if (Luau::CodeGen::isSupported())
185148
Luau::CodeGen::create(L);
186149

lute/require/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target_sources(Lute.Require PRIVATE
44
include/lute/bundlevfs.h
55
include/lute/clivfs.h
66
include/lute/filevfs.h
7+
include/lute/lutevfs.h
78
include/lute/modulepath.h
89
include/lute/options.h
910
include/lute/packagerequirevfs.h
@@ -15,6 +16,7 @@ target_sources(Lute.Require PRIVATE
1516
src/bundlevfs.cpp
1617
src/clivfs.cpp
1718
src/filevfs.cpp
19+
src/lutevfs.cpp
1820
src/modulepath.cpp
1921
src/options.cpp
2022
src/packagerequirevfs.cpp
@@ -26,5 +28,5 @@ target_sources(Lute.Require PRIVATE
2628

2729
target_compile_features(Lute.Require PUBLIC cxx_std_17)
2830
target_include_directories(Lute.Require PUBLIC include)
29-
target_link_libraries(Lute.Require PUBLIC Luau.Require PRIVATE Luau.CLI.lib Luau.Compiler Luau.CodeGen Lute.Std Lute.CLI.Commands Lute.Runtime)
31+
target_link_libraries(Lute.Require PUBLIC Luau.Require PRIVATE Luau.CLI.lib Luau.Compiler Luau.CodeGen Lute.Std Lute.CLI.Commands Lute.Crypto Lute.Fs Lute.IO Lute.Luau Lute.Net Lute.Task Lute.VM Lute.Process Lute.System Lute.Time Lute.Runtime)
3032
target_compile_options(Lute.Require PRIVATE ${LUTE_OPTIONS})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "lute/modulepath.h"
4+
5+
#include "Luau/DenseHash.h"
6+
7+
#include "lua.h"
8+
9+
#include <string>
10+
11+
extern const Luau::DenseHashMap<std::string, lua_CFunction> kLuteModules;
12+
13+
class LuteVfs
14+
{
15+
public:
16+
NavigationStatus resetToPath(const std::string& path);
17+
18+
NavigationStatus toParent();
19+
NavigationStatus toChild(const std::string& name);
20+
21+
bool isModulePresent() const;
22+
std::string getIdentifier() const;
23+
std::optional<std::string> getContents(const std::string& path) const;
24+
25+
ConfigStatus getConfigStatus() const;
26+
std::optional<std::string> getConfig() const;
27+
28+
private:
29+
std::optional<ModulePath> modulePath;
30+
};

lute/require/include/lute/packagerequirevfs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "lute/lutevfs.h"
34
#include "lute/require.h"
45
#include "lute/stdlibvfs.h"
56
#include "lute/userlandvfs.h"
@@ -16,6 +17,7 @@ class RequireVfs : public IRequireVfs
1617

1718
NavigationStatus reset(lua_State* L, std::string_view requirerChunkname) override;
1819
NavigationStatus jumpToAlias(lua_State* L, std::string_view path) override;
20+
NavigationStatus toAliasOverride(lua_State* L, std::string_view aliasUnprefixed) override;
1921
NavigationStatus toAliasFallback(lua_State* L, std::string_view aliasUnprefixed) override;
2022

2123
NavigationStatus toParent(lua_State* L) override;
@@ -48,7 +50,7 @@ class RequireVfs : public IRequireVfs
4850

4951
Package::UserlandVfs userlandVfs;
5052
StdLibVfs stdLibVfs;
51-
std::string lutePath;
53+
LuteVfs luteVfs;
5254
};
5355

5456
} // namespace Package

0 commit comments

Comments
 (0)