forked from Tencent/UnLua
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_CppCallLua.lua
More file actions
Latest commit
40 lines (31 loc) · 985 Bytes
/
Copy path08_CppCallLua.lua
File metadata and controls
40 lines (31 loc) · 985 Bytes
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
--[[
说明:如果需要从C++侧调用Lua,需要将UnLua模块添加到 {工程名}.Build.cs 的依赖配置里
如果需要访问Lua原生API,则还需要添加Lua模块
例如:
PrivateDependencyModuleNames.AddRange(new string[]
{
"UnLua",
"Lua",
});
本示例C++源码:
Source\TPSProject\TutorialBlueprintFunctionLibrary.cpp
]]--
localScreen=require"Tutorials.Screen"
localM=UnLua.Class()
functionM:ReceiveBeginPlay()
localmsg=
[[
—— 本示例来自 "Content/Script/Tutorials.08_CppCallLua.lua"
]]
Screen.Print(msg)
UE.UTutorialBlueprintFunctionLibrary.CallLuaByGlobalTable()
Screen.Print("=================")
UE.UTutorialBlueprintFunctionLibrary.CallLuaByFLuaTable()
end
functionM.CallMe(a, b)
localret=a+b
localmsg=string.format("[Lua]收到来自C++的调用,a=%f b=%f,返回%f", a, b, ret)
Screen.Print(msg)
returnret
end
returnM