forked from Tencent/UnLua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_CustomLoader.lua
41 lines (28 loc) · 1.04 KB
/
12_CustomLoader.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--[[
说明:通过绑定 FUnLuaDelegates::CustomLoadLuaFile 可以实现自定义Lua加载器
演示两种常见的实现供参考:
方式1:查找路径固定,性能更好
方式2:通过package.path查找,更加灵活
本示例C++源码:
Source\TPSProject\TutorialBlueprintFunctionLibrary.cpp
]]
local Screen = require "Tutorials.Screen"
local M = UnLua.Class()
local function print_intro()
local msg =
[[
—— 本示例来自 "Content/Script/Tutorials.12_CustomLoader.lua"
]]
Screen.Print(msg)
end
function M:ReceiveBeginPlay()
print_intro()
UE.UTutorialBlueprintFunctionLibrary.SetupCustomLoader(1)
Screen.Print(string.format("FromCustomLoader1:%s", require("Tutorials")))
package.loaded["Tutorials"] = nil
package.path = package.path .. ";./?/Index.lua"
UE.UTutorialBlueprintFunctionLibrary.SetupCustomLoader(2)
Screen.Print(string.format("FromCustomLoader2:%s", require("Tutorials")))
UE.UTutorialBlueprintFunctionLibrary.SetupCustomLoader(0)
end
return M