-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typedefs and tests for custom instance properties and methods
- Loading branch information
1 parent
9fe3b02
commit 1aa6aef
Showing
6 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
local roblox = require("@lune/roblox") | ||
|
||
local game = roblox.Instance.new("DataModel") | ||
local http = game:GetService("HttpService") :: any | ||
|
||
roblox.implementMethod("HttpService", "GetAsync", function() | ||
-- TODO: Fill in method body | ||
end) | ||
|
||
-- TODO: Fill in rest of test cases here | ||
|
||
http:GetAsync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local roblox = require("@lune/roblox") | ||
|
||
local inst = roblox.Instance.new("Instance") :: any | ||
local part = roblox.Instance.new("Part") :: any | ||
|
||
-- Basic sanity checks for callbacks | ||
|
||
local success = pcall(function() | ||
inst:Wat() | ||
end) | ||
assert(not success, "Nonexistent methods should error") | ||
|
||
roblox.implementMethod("Instance", "Wat", function() end) | ||
|
||
local success2 = pcall(function() | ||
inst:Wat() | ||
end) | ||
assert(success2, "Nonexistent methods should error, unless implemented") | ||
|
||
-- Instance should be passed to callback | ||
|
||
roblox.implementMethod("Instance", "PassingInstanceTest", function(instance) | ||
assert(instance == inst, "Invalid instance was passed to callback") | ||
end) | ||
roblox.implementMethod("Part", "PassingPartTest", function(instance) | ||
assert(instance == part, "Invalid instance was passed to callback") | ||
end) | ||
inst:PassingInstanceTest() | ||
part:PassingPartTest() | ||
|
||
-- Any number of args passed & returned should work | ||
|
||
roblox.implementMethod("Instance", "Echo", function(_, ...) | ||
return ... | ||
end) | ||
|
||
local one, two, three = inst:Echo("one", "two", "three") | ||
assert(one == "one", "implementMethod callback should return proper values") | ||
assert(two == "two", "implementMethod callback should return proper values") | ||
assert(three == "three", "implementMethod callback should return proper values") | ||
|
||
-- Methods implemented by Lune should take precedence | ||
|
||
roblox.implementMethod("Instance", "FindFirstChild", function() | ||
error("unreachable") | ||
end) | ||
inst:FindFirstChild("Test") | ||
part:FindFirstChild("Test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local roblox = require("@lune/roblox") | ||
|
||
local inst = roblox.Instance.new("Instance") :: any | ||
local part = roblox.Instance.new("Part") :: any | ||
|
||
-- Basic sanity checks for callbacks | ||
|
||
local success = pcall(function() | ||
local _ = inst.Wat | ||
end) | ||
assert(not success, "Nonexistent properties should error") | ||
|
||
roblox.implementProperty("Instance", "Wat", function() | ||
return nil | ||
end) | ||
|
||
local success2 = pcall(function() | ||
local _ = inst.Wat | ||
end) | ||
assert(success2, "Nonexistent properties should error, unless implemented") | ||
|
||
-- Instance should be passed to callback | ||
|
||
roblox.implementProperty("Instance", "PassingInstanceTest", function(instance) | ||
assert(instance == inst, "Invalid instance was passed to callback") | ||
return nil | ||
end) | ||
roblox.implementProperty("Part", "PassingPartTest", function(instance) | ||
assert(instance == part, "Invalid instance was passed to callback") | ||
return nil | ||
end) | ||
local _ = inst.PassingInstanceTest | ||
local _ = part.PassingPartTest | ||
|
||
-- Any number of args passed & returned should work | ||
|
||
local counters = {} | ||
roblox.implementProperty("Instance", "Counter", function(instance) | ||
-- FIXME: Instances do not make for unique table keys for some reason ... | ||
local value = counters[tostring(instance)] or 0 | ||
value += 1 | ||
counters[tostring(instance)] = value | ||
return value | ||
end, function(instance, value) | ||
counters[tostring(instance)] = value | ||
end) | ||
|
||
assert(inst.Counter == 1, "implementProperty callback should return proper values") | ||
assert(inst.Counter == 2, "implementProperty callback should return proper values") | ||
assert(inst.Counter == 3, "implementProperty callback should return proper values") | ||
|
||
inst.Counter = 10 | ||
|
||
assert(inst.Counter == 11, "implementProperty callback should set proper values") | ||
assert(inst.Counter == 12, "implementProperty callback should return proper values") | ||
assert(inst.Counter == 13, "implementProperty callback should return proper values") | ||
|
||
-- Properties implemented by Lune should take precedence | ||
|
||
roblox.implementProperty("Instance", "Parent", function() | ||
error("unreachable") | ||
end) | ||
local _ = inst.Parent | ||
local _ = part.Parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters