Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
634caf5
path join shouldn't mutate argument objects
skberkeley Oct 21, 2025
843db08
require by path
skberkeley Oct 21, 2025
c650639
ariel comments
skberkeley Oct 22, 2025
71105d7
create @std wrapper for luau around @lute/luau
skberkeley Oct 22, 2025
3419596
require takes a pathlike
skberkeley Oct 22, 2025
97ce393
move loadbypath into std/luau
skberkeley Oct 22, 2025
58c0abf
update load_luau to reflect new signature
skberkeley Oct 22, 2025
16a8385
Merge branch 'primary' into skanosue/requirebypath
skberkeley Oct 22, 2025
88fb11a
rare useful copilot feedback
skberkeley Oct 23, 2025
7c1b88f
Merge branch 'primary' into skanosue/requirebypath
skberkeley Oct 23, 2025
6ad70b4
Merge branch 'primary' into skanosue/requirebypath
skberkeley Oct 23, 2025
cf5279e
Merge branch 'primary' into skanosue/requirebypath
skberkeley Oct 24, 2025
7fd1d72
varun comments
skberkeley Oct 24, 2025
74a6765
debug ubuntu
skberkeley Oct 25, 2025
5d1c38d
Merge branch 'primary' into ubuntu-debug
skberkeley Oct 25, 2025
dbffb36
use tmpdir
skberkeley Oct 25, 2025
9a4b7f6
list dir entries
skberkeley Oct 25, 2025
965bdb7
wrong list dir path
skberkeley Oct 25, 2025
51d0ea9
hell o world
skberkeley Oct 25, 2025
632ad85
test args
skberkeley Oct 25, 2025
7b144de
loadbypath locally
skberkeley Oct 27, 2025
263eddd
original test
skberkeley Oct 27, 2025
dd5fa87
check output first
skberkeley Oct 27, 2025
4e435d4
fs the arg
skberkeley Oct 27, 2025
4c954de
more prints in load
skberkeley Oct 27, 2025
97e026e
exit before luau.load
skberkeley Oct 27, 2025
1527a6f
move require?
skberkeley Oct 27, 2025
bd4df85
print stderr, compile errors?
skberkeley Oct 27, 2025
5d1c28a
just try compiling
skberkeley Oct 27, 2025
56db42d
compile directly
skberkeley Oct 27, 2025
dbdfe44
compile in requirer
skberkeley Oct 27, 2025
65410bf
fix memory leak hopefully
skberkeley Oct 27, 2025
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
2 changes: 1 addition & 1 deletion definitions/luau.luau
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ function luau.compile(source: string): Bytecode
error("not implemented")
end

function luau.load(bytecode: Bytecode, chunkname: string?, env: { [any]: any }?): (...any) -> ...any
function luau.load(bytecode: Bytecode, chunkname: string, env: { [any]: any }?): (...any) -> ...any
error("not implemented")
end

Expand Down
2 changes: 1 addition & 1 deletion examples/compile.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local luau = require("@lute/luau")
local luau = require("@std/luau")

local bytecode_container = luau.compile('return "Hello, world!"')

Expand Down
2 changes: 1 addition & 1 deletion examples/linter.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local fs = require("@std/fs")
local luau = require("@lute/luau")
local luau = require("@std/luau")

local pp = require("@batteries/pp")

Expand Down
2 changes: 1 addition & 1 deletion examples/parsing.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local luau = require("@lute/luau")
local luau = require("@std/luau")

local pretty = require("@batteries/pp")

Expand Down
20 changes: 13 additions & 7 deletions lute/luau/src/luau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,14 @@ int compile_luau(lua_State* L)

std::string bytecode = Luau::compile(std::string(source, source_size), opts);

std::string* userdata = static_cast<std::string*>(lua_newuserdatatagged(L, sizeof(std::string), kCompilerResultTag));
std::string* userdata = static_cast<std::string*>(lua_newuserdatadtor(
L,
sizeof(std::string),
[](void* ptr)
{
static_cast<std::string*>(ptr)->~basic_string();
}
));

new (userdata) std::string(std::move(bytecode));

Expand All @@ -2656,13 +2663,12 @@ int compile_luau(lua_State* L)

int load_luau(lua_State* L)
{
const std::string* bytecode_string = static_cast<std::string*>(luaL_checkudata(L, 1, COMPILE_RESULT_TYPE));
const char* path = luaL_optlstring(L, 2, "=luau.load", nullptr);
std::string chunk_name = path;
if (chunk_name != "=luau.load")
chunk_name.insert(0, "@");
const std::string* bytecodeString = static_cast<std::string*>(luaL_checkudata(L, 1, COMPILE_RESULT_TYPE));
const char* chunkname = luaL_checkstring(L, 2);
int envIndex = lua_isnoneornil(L, 3) ? 0 : 3;

luau_load(L, chunk_name.c_str(), bytecode_string->c_str(), bytecode_string->length(), lua_gettop(L) > 2 ? 3 : 0);
if (luau_load(L, chunkname, bytecodeString->c_str(), bytecodeString->length(), envIndex) != 0)
lua_error(L);

return 1;
}
Expand Down
7 changes: 3 additions & 4 deletions lute/runtime/include/lute/userdatas.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

// all tags count down from 128
constexpr int kDurationTag = 127;
constexpr int kInstantTag = 126;
constexpr int kCompilerResultTag = 125;
constexpr int kWatchHandleTag = 124;
constexpr int kDurationTag = 127;
constexpr int kInstantTag = 126;
constexpr int kWatchHandleTag = 125;
183 changes: 183 additions & 0 deletions lute/std/libs/luau.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
local luteLuau = require("@lute/luau")

local fs = require("@lute/fs")
local path = require("@std/path")

local luau = {}

-- Export all types from luteLuau
export type Position = luteLuau.Position
export type Location = luteLuau.Location

export type Whitespace = luteLuau.Whitespace
export type SingleLineComment = luteLuau.SingleLineComment
export type MultiLineComment = luteLuau.MultiLineComment

export type Trivia = luteLuau.Trivia

export type Token<Kind = string> = luteLuau.Token<Kind>

export type Eof = luteLuau.Eof

export type Pair<T, Separator> = luteLuau.Pair<T, Separator>
export type Punctuated<T, Separator = ","> = luteLuau.Punctuated<T, Separator>

export type AstLocal = luteLuau.AstLocal

export type AstExprGroup = luteLuau.AstExprGroup

export type AstExprConstantNil = luteLuau.AstExprConstantNil

export type AstExprConstantBool = luteLuau.AstExprConstantBool

export type AstExprConstantNumber = luteLuau.AstExprConstantNumber

export type AstExprConstantString = luteLuau.AstExprConstantString

export type AstExprLocal = luteLuau.AstExprLocal

export type AstExprGlobal = luteLuau.AstExprGlobal

export type AstExprVarargs = luteLuau.AstExprVarargs

export type AstExprCall = luteLuau.AstExprCall

export type AstExprIndexName = luteLuau.AstExprIndexName

export type AstExprIndexExpr = luteLuau.AstExprIndexExpr

export type AstFunctionBody = luteLuau.AstFunctionBody

export type AstExprAnonymousFunction = luteLuau.AstExprAnonymousFunction

export type AstExprTableItem = luteLuau.AstExprTableItem

export type AstExprTable = luteLuau.AstExprTable

export type AstExprUnary = luteLuau.AstExprUnary

export type AstExprBinary = luteLuau.AstExprBinary

export type AstExprInterpString = luteLuau.AstExprInterpString

export type AstExprTypeAssertion = luteLuau.AstExprTypeAssertion

export type AstExprIfElseIfs = luteLuau.AstExprIfElseIfs

export type AstExprIfElse = luteLuau.AstExprIfElse

export type AstExpr = luteLuau.AstExpr

export type AstStatBlock = luteLuau.AstStatBlock

export type AstStatElseIf = luteLuau.AstStatElseIf

export type AstStatIf = luteLuau.AstStatIf

export type AstStatWhile = luteLuau.AstStatWhile

export type AstStatRepeat = luteLuau.AstStatRepeat

export type AstStatBreak = luteLuau.AstStatBreak

export type AstStatContinue = luteLuau.AstStatContinue

export type AstStatReturn = luteLuau.AstStatReturn

export type AstStatExpr = luteLuau.AstStatExpr

export type AstStatLocal = luteLuau.AstStatLocal

export type AstStatFor = luteLuau.AstStatFor

export type AstStatForIn = luteLuau.AstStatForIn

export type AstStatAssign = luteLuau.AstStatAssign

export type AstStatCompoundAssign = luteLuau.AstStatCompoundAssign

export type AstAttribute = luteLuau.AstAttribute

export type AstStatFunction = luteLuau.AstStatFunction

export type AstStatLocalFunction = luteLuau.AstStatLocalFunction

export type AstStatTypeAlias = luteLuau.AstStatTypeAlias

export type AstStatTypeFunction = luteLuau.AstStatTypeFunction

export type AstStat = luteLuau.AstStat

export type AstGenericType = luteLuau.AstGenericType

export type AstGenericTypePack = luteLuau.AstGenericTypePack

export type AstTypeReference = luteLuau.AstTypeReference

export type AstTypeSingletonBool = luteLuau.AstTypeSingletonBool

export type AstTypeSingletonString = luteLuau.AstTypeSingletonString

export type AstTypeTypeof = luteLuau.AstTypeTypeof

export type AstTypeGroup = luteLuau.AstTypeGroup

export type AstTypeOptional = luteLuau.AstTypeOptional

export type AstTypeUnion = luteLuau.AstTypeUnion

export type AstTypeIntersection = luteLuau.AstTypeIntersection

export type AstTypeArray = luteLuau.AstTypeArray

export type AstTypeTableItem = luteLuau.AstTypeTableItem

export type AstTypeTable = luteLuau.AstTypeTable

export type AstTypeFunctionParameter = luteLuau.AstTypeFunctionParameter

export type AstTypeFunction = luteLuau.AstTypeFunction

export type AstType = luteLuau.AstType

export type AstTypePackExplicit = luteLuau.AstTypePackExplicit

export type AstTypePackGeneric = luteLuau.AstTypePackGeneric

export type AstTypePackVariadic = luteLuau.AstTypePackVariadic

export type AstTypePack = luteLuau.AstTypePack

export type ParseResult = luteLuau.ParseResult

export type Bytecode = luteLuau.Bytecode

function luau.parse(source: string): ParseResult
return luteLuau.parse(source)
end

function luau.parseexpr(source: string): AstExpr
return luteLuau.parseexpr(source)
end

function luau.compile(source: string): Bytecode
return luteLuau.compile(source)
end

function luau.load(bytecode: Bytecode, chunkname: string?, env: { [any]: any }?): (...any) -> ...any
return luteLuau.load(bytecode, if chunkname ~= nil then `@{chunkname}` else "=luau.load", env)
end

function luau.loadbypath(requirePath: path.pathlike): any
local requirePathStr = if typeof(requirePath) == "string" then requirePath else path.format(requirePath)
print(`got script path: {requirePathStr}`)
local migrationHandle = fs.open(requirePathStr, "r")
print(`opened file handle`)
local migrationBytecode = luau.compile(fs.read(migrationHandle))
print(`compiled bytecode`)
fs.close(migrationHandle)
print(`closed file handle`)
return luau.load(migrationBytecode, requirePathStr)()
end

return luau
9 changes: 3 additions & 6 deletions lute/std/libs/path/posix/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ function posix.join(...: pathlike): path
}
end

local path: path
if typeof(parts[1]) == "string" then
path = posix.parse(parts[1])
else
path = {
local path: path = if typeof(parts[1]) == "string"
then posix.parse(parts[1])
else {
parts = table.clone((parts[1] :: path).parts),
absolute = (parts[1] :: path).absolute,
}
end

for i = 2, #parts do
joinHelper(path, parts[i])
Expand Down
9 changes: 3 additions & 6 deletions lute/std/libs/path/win32/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,13 @@ function win32.join(...: pathlike): path
}
end

local path: path
if typeof(parts[1]) == "string" then
path = win32.parse(parts[1])
else
path = {
local path: path = if typeof(parts[1]) == "string"
then win32.parse(parts[1])
else {
parts = table.clone((parts[1] :: path).parts),
kind = (parts[1] :: path).kind,
driveLetter = (parts[1] :: path).driveLetter,
}
end

for i = 2, #parts do
joinHelper(path, parts[i])
Expand Down
2 changes: 1 addition & 1 deletion lute/std/libs/syntax/parser.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--!strict

local luau = require("@lute/luau")
local luau = require("@std/luau")

--- Parses Luau source code into an AstStatBlock
local function parse(source: string): luau.AstStatBlock
Expand Down
2 changes: 1 addition & 1 deletion lute/std/libs/syntax/printer.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--!strict
local luau = require("@lute/luau")
local luau = require("@std/luau")
local visitor = require("./visitor")

local function exhaustiveMatch(value: never): never
Expand Down
2 changes: 1 addition & 1 deletion lute/std/libs/syntax/visitor.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--!strict

local luau = require("@lute/luau")
local luau = require("@std/luau")

export type Visitor = {
visitBlock: (luau.AstStatBlock) -> boolean,
Expand Down
2 changes: 2 additions & 0 deletions lute/std/libs/system/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ return table.freeze({
uptime = system.uptime,
cpus = system.cpus,

tmpdir = tmpdir,

-- boolean properties
win32 = platforminfo.win32,
linux = platforminfo.linux,
Expand Down
Loading