Skip to content

Commit 4eb662e

Browse files
committed
Rename funciton with pascal case and move to __FCMBase.lua
1 parent 15c1737 commit 4eb662e

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

src/library/mixin.lua

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,6 @@ function mixin_private.apply_mixin_foundation(object)
760760
return mixin_private.create_fluid_proxy(prop)
761761
end
762762

763-
if not prop and k == "fallback_call" then
764-
return mixin_public.fallback_call
765-
end
766-
767763
return prop
768764
end
769765

@@ -1053,24 +1049,4 @@ function mixin_public.eachentry(region, layer)
10531049
end
10541050
end
10551051

1056-
--[[
1057-
% fallback_call
1058-
1059-
Checks the existence of a class method before calling it. If the method exists, it returns
1060-
as expected. If the method does not exist, it returns the fallback_value. This function allows
1061-
a script to call a method that does not exist in earlier versions of Lua (specifically, in JW Lua.)
1062-
1063-
@ instance (userdata) The class instance on which to call the method.
1064-
@ method_name (string) The name of the method to return.
1065-
@ fallback_value (any) The value that will be returned if the method does not exist. If this value is `nil`, the function returns `self`.
1066-
@ additional_parameters (...) The additional parameters of the method.
1067-
]]
1068-
function mixin_public.fallback_call(instance, method_name, fallback_value, ...)
1069-
if not instance[method_name] then
1070-
return fallback_value or instance
1071-
end
1072-
1073-
return instance[method_name](instance, ...)
1074-
end
1075-
10761052
return mixin

src/mixin/__FCMBase.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- Author: Robert Patterson
2+
-- Date: January 20, 2024
3+
--[[
4+
$module __FCMBase
5+
6+
## Summary of Modifications
7+
- Add method _FallbackCall to gracefully allow skipping missing methods in earlier Lua versions
8+
]] --
9+
local mixin = require("library.mixin")
10+
local mixin_helper = require("library.mixin_helper")
11+
12+
local class = {Methods = {}}
13+
local methods = class.Methods
14+
15+
16+
--[[
17+
% _FallbackCall
18+
19+
Checks the existence of a class method before calling it. If the method exists, it returns
20+
as expected. If the method does not exist, it returns the fallback_value. This function allows
21+
a script to call a method that does not exist in earlier versions of Lua (specifically, in JW Lua)
22+
and get a default return value in that case.
23+
24+
@ self (userdata) The class instance on which to call the method.
25+
@ method_name (string) The name of the method to return.
26+
@ fallback_value (any) The value that will be returned if the method does not exist. If this value is `nil`, the function returns `self`.
27+
@ additional_parameters (...) The additional parameters of the method.
28+
]]
29+
function methods:_FallbackCall(method_name, fallback_value, ...)
30+
if not self[method_name] then
31+
return fallback_value or self
32+
end
33+
34+
return self[method_name](self, ...)
35+
end
36+
37+
return class

0 commit comments

Comments
 (0)