Skip to content

Commit 9d7d924

Browse files
committed
rename library
1 parent 8f08cd4 commit 9d7d924

File tree

7 files changed

+68
-68
lines changed

7 files changed

+68
-68
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Luau Hotreload
1+
# Graft
22

3-
[![GitHub License](https://img.shields.io/github/license/ewd3v/luau_hotreload)](https://opensource.org/licenses/MIT)
4-
[![CI Status](https://github.com/ewd3v/luau_hotreload/actions/workflows/ci.yaml/badge.svg)](https://github.com/ewd3v/luau_hotreload/actions/workflows/ci.yaml)
3+
[![GitHub License](https://img.shields.io/github/license/ewd3v/luau_graft)](https://opensource.org/licenses/MIT)
4+
[![CI Status](https://github.com/ewd3v/luau_graft/actions/workflows/ci.yaml/badge.svg)](https://github.com/ewd3v/luau_graft/actions/workflows/ci.yaml)
55

6-
> Hot reloading for luau
6+
> Hot reloading for Luau

pesde.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is automatically @generated by pesde.
22
# It is not intended for manual editing.
33
format = 2
4-
name = "ewdev/hotreload"
4+
name = "ewdev/graft"
55
version = "0.0.0"
66
target = "luau"
77

pesde.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name = "ewdev/hotreload"
1+
name = "ewdev/graft"
22
version = "0.0.0"
3-
description = "Hot reloading for luau"
3+
description = "Hot reloading for Luau"
44
authors = ["EwDev (https://ewdev.net/)"]
5-
repository = "https://github.com/ewd3v/luau_hotreload"
5+
repository = "https://github.com/ewd3v/luau_graft"
66
license = "MIT"
77
includes = ["src/**", "pesde.toml", "LICENSE", "README.md", "fiu/Source.lua"]
88

src/init.luau

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@ type Module = VM.Module
77
type Settings = VM.Settings
88

99
--[=[
10-
@class HotReload
10+
@class Graft
1111
12-
An object used to hold information relevant to hot reloading a certain Luau module / file / script.
12+
An object used to hold information relevant for hot reloading a certain Luau module / file / script.
1313
]=]
1414

15-
local HotReload = {} :: impl
16-
HotReload.__index = HotReload
15+
local Graft = {} :: impl
16+
Graft.__index = Graft
1717

1818
type self = {
1919
Source: string,
2020
Interface: Interface,
2121
Module: Module?,
2222

2323
_waitingForModule: { thread },
24-
_reloadThread: thread?,
24+
_patchThread: thread?,
2525
_main: ((...any) -> ...any)?,
2626

2727
Settings: Settings,
2828
}
2929
type impl = {
3030
__index: impl,
3131

32-
new: (interface: Interface) -> HotReload,
32+
new: (interface: Interface) -> Graft,
3333

34-
IsHotReloaded: () -> boolean,
35-
Reload: (self: HotReload) -> (),
36-
Run: (self: HotReload, ...any) -> ...any,
34+
IsGrafted: () -> boolean,
35+
Patch: (self: Graft) -> (),
36+
Run: (self: Graft, ...any) -> ...any,
3737
}
3838

39-
export type HotReload = typeof(setmetatable({} :: self, HotReload))
39+
export type Graft = typeof(setmetatable({} :: self, Graft))
4040

4141
local function getDefaultSettings(): Settings
4242
local settings = VM.luau_newsettings()
4343

44-
local isHotReloaded = HotReload.IsHotReloaded
44+
local isGrafted = Graft.IsGrafted
4545
settings.callHooks = {
4646
callHook = function(func, ...)
47-
if func ~= isHotReloaded then
47+
if func ~= isGrafted then
4848
return func, ...
4949
end
5050

@@ -58,53 +58,53 @@ local function getDefaultSettings(): Settings
5858
end
5959

6060
--[=[
61-
Creates a new [HotReload] object with the provided [Interface].
61+
Creates a new [Graft] object with the provided [Interface].
6262
]=]
63-
function HotReload.new(interface: Interface, source: string?): HotReload
64-
local self = setmetatable({}, HotReload)
63+
function Graft.new(interface: Interface, source: string?): Graft
64+
local self = setmetatable({}, Graft)
6565

6666
--[=[
67-
@within HotReload
67+
@within Graft
6868
@prop Source string
6969
7070
The name / source of the Luau module thats being hot reloaded by this object.
7171
]=]
7272
self.Source = source or debug.info(2, "s")
7373

7474
--[=[
75-
@within HotReload
75+
@within Graft
7676
@prop Interface Interface
7777
78-
A reference to the [Interface] used to create this HotReload object.
78+
A reference to the [Interface] used to create this Graft object.
7979
]=]
8080
self.Interface = interface
8181

8282
--[=[
83-
@within HotReload
83+
@within Graft
8484
@prop Module Module
8585
]=]
8686
self.Module = nil
8787

8888
--[=[
89-
@within HotReload
89+
@within Graft
9090
@prop _waitingForBytecode { thread }
9191
@private
9292
93-
A list of threads that are currently yielding and that should be resumed when [HotReload.Module] is available.
93+
A list of threads that are currently yielding and that should be resumed when [Graft.Module] is available.
9494
]=]
9595
self._waitingForModule = {}
9696

9797
--[=[
98-
@within HotReload
99-
@prop _reloadThread thread
98+
@within Graft
99+
@prop _patchThread thread
100100
@private
101101
102-
The thread that's currently fetching the updated code and reloading the code.
102+
The thread that's currently fetching the updated code and patching the code.
103103
]=]
104-
self._reloadThread = nil
104+
self._patchThread = nil
105105

106106
--[=[
107-
@within HotReload
107+
@within Graft
108108
@prop _main ((...any) -> ...any)?
109109
@private
110110
@@ -113,35 +113,35 @@ function HotReload.new(interface: Interface, source: string?): HotReload
113113
self._main = nil
114114

115115
--[=[
116-
@within HotReload
116+
@within Graft
117117
@prop Settings Settings
118118
119119
The [Fiu] settings that should be used.
120120
]=]
121121
self.Settings = getDefaultSettings()
122122

123-
self:Reload()
123+
self:Patch()
124124
return self
125125
end
126126

127127
--[=[
128-
Returns true if the current environment is being hot reloaded.
129-
If it is you shouldn't really try hot loading it again.
128+
Returns true if the current environment can be hot reloaded with [Graft].
129+
If it is you shouldn't try hot loading it again.
130130
]=]
131-
function HotReload.IsHotReloaded(): boolean
131+
function Graft.IsGrafted(): boolean
132132
return false
133133
end
134134

135-
local function reload(self: HotReload)
135+
local function patch(self: Graft)
136136
local bytecodeSuccess, bytecode = pcall(self.Interface.GetBytecode)
137137
if not bytecodeSuccess then
138-
print(`[HotReload] Failed to retrieve bytecode for {self.Source}: {bytecode}`)
138+
print(`[Graft] Failed to retrieve bytecode for {self.Source}: {bytecode}`)
139139
return
140140
end
141141

142142
local deserializeSuccess, deserialized = pcall(VM.luau_deserialize, bytecode :: any, self.Settings)
143143
if not deserializeSuccess then
144-
print(`[HotReload] Failed to deserialize bytecode for {self.Source}: {deserialized}`)
144+
print(`[Graft] Failed to deserialize bytecode for {self.Source}: {deserialized}`)
145145
end
146146

147147
local module = self.Module
@@ -157,7 +157,7 @@ local function reload(self: HotReload)
157157
end
158158

159159
local functionChangeError =
160-
`[HotReload] Changing the amount of functions or rearranging them is not yet supported. Not hot reloading. (source: {self.Source})`
160+
`[Graft] Changing the amount of functions or rearranging them is not yet supported. Not patching. (source: {self.Source})`
161161

162162
if #module.protoList ~= #deserialized.protoList then
163163
print(functionChangeError)
@@ -168,7 +168,7 @@ local function reload(self: HotReload)
168168
local dProto = deserialized.protoList[index]
169169
if proto.nups ~= dProto.nups then
170170
print(
171-
`[HotReload] Changing the amount of upvalues that a function has is not yet supported. Not hot reloading. (line: {dProto.linedefined}, function name: {dProto.debugname}, source: {self.Source})`
171+
`[Graft] Changing the amount of upvalues that a function has is not yet supported. Not patching. (line: {dProto.linedefined}, function name: {dProto.debugname}, source: {self.Source})`
172172
)
173173
return
174174
end
@@ -184,7 +184,7 @@ local function reload(self: HotReload)
184184
end
185185
end
186186

187-
print(`[HotReload] Hot reloading {self.Source}`)
187+
print(`[Graft] Patching {self.Source}`)
188188

189189
module.stringList = deserialized.stringList
190190
module.typesVersion = deserialized.typesVersion
@@ -214,21 +214,21 @@ end
214214
--[=[
215215
Asks the [Interface] for the updated source code and then hot reloads the code.
216216
]=]
217-
function HotReload:Reload()
218-
if self._reloadThread then
219-
coroutine.close(self._reloadThread)
217+
function Graft:Patch()
218+
if self._patchThread then
219+
coroutine.close(self._patchThread)
220220
end
221221

222-
self._reloadThread = coroutine.create(reload)
223-
coroutine.resume(self._reloadThread :: any, self)
222+
self._patchThread = coroutine.create(patch)
223+
coroutine.resume(self._patchThread :: any, self)
224224
end
225225

226226
--[=[
227-
Runs the luau module.
227+
Runs the Luau module.
228228
229229
@yields
230230
]=]
231-
function HotReload:Run(...: any): ...any
231+
function Graft:Run(...: any): ...any
232232
local module = self.Module
233233
if not module then
234234
table.insert(self._waitingForModule, coroutine.running())
@@ -242,4 +242,4 @@ function HotReload:Run(...: any): ...any
242242
return (self._main :: any)(...)
243243
end
244244

245-
return HotReload
245+
return Graft

src/interface.luau

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
--[=[
44
@class Interface
55
6-
An interface is required in order to create a [HotReload] object.
6+
An interface is required in order to create a [Graft] object.
77
It provides all the required information to it that it needs in order to perform hot reloading (mainly watching for changes and reading / compiling code sources).
88
9-
The main reason why this can't be included in the library by default is because raw luau can't actually read it's own source code or watch for io changes.
9+
The main reason why this can't be included in the library by default is because pure Luau can't actually read it's own source code or watch for io changes.
1010
Because of this, there's really no standard to the implementation that runtimes that do support this chooses to have.
1111
1212
It's planned in the future to create packages for these runtimes which will implement this interface for you. Which will be listed here.
@@ -22,9 +22,9 @@ export type Interface = {
2222
@return buffer
2323
@yields
2424
25-
Function that will compile and return the bytecode of the luau module to run.
25+
Function that will compile and return the bytecode of the Luau module to run.
2626
27-
This function may get called multiple times, once while constructing the [HotReload] object, and then whenever [HotReload:Reload] gets called.
27+
This function may get called multiple times, once while constructing the [Graft] object, and then whenever [Graft:Patch] gets called.
2828
2929
The function may throw errors, in which case the error will get caught and hot reloading won't happen until the next reload.
3030

src/vm.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
--[=[
44
@class VM
5-
@external Fiu https://github.com/rce-incorporated/Fiu/blob/main/Source.lua
5+
@external Fiu https://github.com/rce-incorporated/Fiu
66
77
[Fiu] VM
88
]=]

tests/init.luau

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ end
66
local luau = require("@lune/luau")
77
local task = require("@lune/task")
88

9-
local HotReload = require("./src")
9+
local Graft = require("./src")
1010

1111
local sourcecode = [[
1212
local task = require("@lune/task")
13-
local HotReload, a, b = ...
13+
local Graft, a, b = ...
1414
local ret = { a, b }
1515
local function test()
1616
table.insert(ret, "hi!")
1717
end
1818
test()
1919
task.wait(1)
2020
test()
21-
return HotReload.IsHotReloaded(), ret
21+
return Graft.IsGrafted(), ret
2222
]]
2323

2424
local sourcecode2 = [[
2525
local task = require("@lune/task")
26-
local HotReload, a, b = ...
26+
local Graft, a, b = ...
2727
local ret = { a, b }
2828
local function test()
2929
table.insert(ret, "goodbye!")
@@ -32,10 +32,10 @@ end
3232
test()
3333
task.wait(1)
3434
test()
35-
return HotReload.IsHotReloaded(), ret
35+
return Graft.IsGrafted(), ret
3636
]]
3737

38-
local hotReload = HotReload.new({
38+
local graft = Graft.new({
3939
GetBytecode = function(): buffer
4040
print("compiling bytecode...")
4141
return buffer.fromstring(luau.compile(sourcecode))
@@ -44,12 +44,12 @@ local hotReload = HotReload.new({
4444

4545
task.defer(function()
4646
sourcecode = sourcecode2
47-
hotReload:Reload()
47+
graft:Patch()
4848
end)
4949

50-
local isHotReloaded, ret = hotReload:Run(HotReload, "test1", "test2")
51-
assert(isHotReloaded == true, ".IsHotReloaded() should return true in hot reloaded environments")
52-
assert(HotReload.IsHotReloaded() == false, ".IsHotReloaded() should return false outside hot reloaded environments")
50+
local isGrafted, ret = graft:Run(Graft, "test1", "test2")
51+
assert(isGrafted == true, ".IsGrafted() should return true in hot reloaded environments")
52+
assert(graft.IsGrafted() == false, ".IsGrafted() should return false outside hot reloaded environments")
5353

5454
assert(#ret == 5, "bad return amount")
5555
assert(ret[1] == "test1", "bad return")

0 commit comments

Comments
 (0)