├── README.md └── UnLua ├── Content ├── ActorComponentTemplate.lua ├── ActorTemplate.lua ├── AnimInstanceTemplate.lua ├── UnLua.lua ├── UnLuaPerformanceTestProxy.lua └── UserWidgetTemplate.lua ├── Resources ├── Icon128.png └── icon_luatemplate_40x.png ├── Source ├── ThirdParty │ ├── LibCjson │ │ ├── LibCjson.Build.cs │ │ ├── LibCjson.cpp │ │ ├── LibCjson.h │ │ ├── dtoa.c │ │ ├── dtoa_config.h │ │ ├── fpconv.h │ │ ├── g_fmt.c │ │ ├── lua │ │ │ ├── cjson │ │ │ │ └── util.lua │ │ │ ├── json2lua.lua │ │ │ └── lua2json.lua │ │ ├── lua_cjson.c │ │ ├── strbuf.c │ │ └── strbuf.h │ ├── LibLpeg │ │ ├── HISTORY │ │ ├── LibLpeg.Build.cs │ │ ├── LibLpeg.cpp │ │ ├── LibLpeg.h │ │ ├── lpcap.c │ │ ├── lpcap.h │ │ ├── lpcode.c │ │ ├── lpcode.h │ │ ├── lpeg-128.gif │ │ ├── lpeg.html │ │ ├── lpprint.c │ │ ├── lpprint.h │ │ ├── lptree.c │ │ ├── lptree.h │ │ ├── lptypes.h │ │ ├── lpvm.c │ │ ├── lpvm.h │ │ ├── makefile │ │ ├── re.html │ │ ├── re.lua │ │ └── test.lua │ ├── LibLuacrypt │ │ ├── LibLuacrypt.Build.cs │ │ ├── LibLuacrypt.cpp │ │ ├── LibLuacrypt.h │ │ ├── lsha1.c │ │ └── lua-crypt.c │ ├── LibLuasocket │ │ ├── LibLuasocket.Build.cs │ │ ├── LibLuasocket.cpp │ │ ├── LibLuasocket.h │ │ ├── auxiliar.c │ │ ├── auxiliar.h │ │ ├── buffer.c │ │ ├── buffer.h │ │ ├── except.c │ │ ├── except.h │ │ ├── ftp.lua.inc │ │ ├── headers.lua.inc │ │ ├── http.lua.inc │ │ ├── inet.c │ │ ├── inet.h │ │ ├── io.c │ │ ├── io.h │ │ ├── ltn12.lua.inc │ │ ├── luasocket.c │ │ ├── luasocket.h │ │ ├── mbox.lua.inc │ │ ├── mime.c │ │ ├── mime.h │ │ ├── mime.lua.inc │ │ ├── options.c │ │ ├── options.h │ │ ├── pierror.h │ │ ├── select.c │ │ ├── select.h │ │ ├── smtp.lua.inc │ │ ├── socket.h │ │ ├── socket.lua.inc │ │ ├── tcp.c │ │ ├── tcp.h │ │ ├── timeout.c │ │ ├── timeout.h │ │ ├── tp.lua.inc │ │ ├── udp.c │ │ ├── udp.h │ │ ├── url.lua.inc │ │ ├── usocket.c │ │ ├── usocket.h │ │ ├── wsocket.c │ │ └── wsocket.h │ ├── LibSproto │ │ ├── LibSproto.Build.cs │ │ ├── LibSproto.cpp │ │ ├── LibSproto.h │ │ ├── lsproto.c │ │ ├── msvcint.h │ │ ├── sproto.c │ │ └── sproto.h │ └── Lua │ │ ├── Lua.Build.cs │ │ ├── binaries │ │ ├── Mac │ │ │ └── liblua.dylib │ │ └── Win64 │ │ │ ├── Lua.dll │ │ │ └── Lua.lib │ │ ├── include │ │ ├── lauxlib.h │ │ ├── lfunc.h │ │ ├── llimits.h │ │ ├── lmem.h │ │ ├── lobject.h │ │ ├── lstate.h │ │ ├── ltm.h │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luaconf.h │ │ ├── lualib.h │ │ └── lzio.h │ │ └── lib │ │ ├── Android │ │ ├── ARM64 │ │ │ └── liblua.a │ │ └── ARMv7 │ │ │ └── liblua.a │ │ ├── Mac │ │ └── liblua.a │ │ ├── Win64 │ │ └── Lua.lib │ │ └── iOS │ │ └── liblua.a ├── UnLua │ ├── Private │ │ ├── BaseLib │ │ │ ├── LuaLib_Array.cpp │ │ │ ├── LuaLib_Class.cpp │ │ │ ├── LuaLib_Delegate.cpp │ │ │ ├── LuaLib_Map.cpp │ │ │ ├── LuaLib_MulticastDelegate.cpp │ │ │ ├── LuaLib_Object.cpp │ │ │ ├── LuaLib_PrimitiveTypes.cpp │ │ │ ├── LuaLib_Set.cpp │ │ │ └── LuaLib_World.cpp │ │ ├── CollisionHelper.cpp │ │ ├── CollisionHelper.h │ │ ├── Containers │ │ │ ├── LuaArray.h │ │ │ ├── LuaMap.h │ │ │ └── LuaSet.h │ │ ├── DefaultParamCollection.cpp │ │ ├── DefaultParamCollection.h │ │ ├── DelegateHelper.cpp │ │ ├── DelegateHelper.h │ │ ├── LuaContext.cpp │ │ ├── LuaContext.h │ │ ├── LuaCore.cpp │ │ ├── LuaCore.h │ │ ├── LuaDynamicBinding.cpp │ │ ├── LuaDynamicBinding.h │ │ ├── LuaFunctionInjection.cpp │ │ ├── LuaFunctionInjection.h │ │ ├── MathLib │ │ │ ├── LuaLib_FColor.cpp │ │ │ ├── LuaLib_FIntPoint.cpp │ │ │ ├── LuaLib_FIntVector.cpp │ │ │ ├── LuaLib_FLinearColor.cpp │ │ │ ├── LuaLib_FQuat.cpp │ │ │ ├── LuaLib_FRotator.cpp │ │ │ ├── LuaLib_FTransform.cpp │ │ │ ├── LuaLib_FVector.cpp │ │ │ ├── LuaLib_FVector2.cpp │ │ │ ├── LuaLib_FVector4.cpp │ │ │ └── LuaLib_Math.h │ │ ├── ReflectionUtils │ │ │ ├── ClassDesc.cpp │ │ │ ├── ClassDesc.h │ │ │ ├── EnumDesc.h │ │ │ ├── FieldDesc.h │ │ │ ├── FunctionDesc.cpp │ │ │ ├── FunctionDesc.h │ │ │ ├── PropertyCreator.cpp │ │ │ ├── PropertyCreator.h │ │ │ ├── PropertyDesc.cpp │ │ │ ├── PropertyDesc.h │ │ │ ├── ReflectionRegistry.cpp │ │ │ └── ReflectionRegistry.h │ │ ├── Tests │ │ │ ├── UnLuaPerformanceTestProxy.cpp │ │ │ └── UnLuaPerformanceTestProxy.h │ │ ├── UEObjectReferencer.h │ │ ├── UnLua.cpp │ │ ├── UnLuaBase.cpp │ │ ├── UnLuaCompatibility.h │ │ ├── UnLuaDebugBase.cpp │ │ ├── UnLuaDelegates.cpp │ │ ├── UnLuaManager.cpp │ │ ├── UnLuaManager.h │ │ ├── UnLuaModule.cpp │ │ └── UnLuaPrivate.h │ ├── Public │ │ ├── UnLua.h │ │ ├── UnLua.inl │ │ ├── UnLuaBase.h │ │ ├── UnLuaDebugBase.h │ │ ├── UnLuaDelegates.h │ │ ├── UnLuaEx.h │ │ ├── UnLuaEx.inl │ │ ├── UnLuaInterface.h │ │ └── UnLuaTemplate.h │ └── UnLua.Build.cs ├── UnLuaDefaultParamCollector │ ├── Private │ │ └── UnLuaDefaultParamCollector.cpp │ └── UnLuaDefaultParamCollector.Build.cs ├── UnLuaEditor │ ├── Classes │ │ └── Commandlets │ │ │ └── UnLuaIntelliSenseCommandlet.h │ ├── Private │ │ ├── Commandlets │ │ │ └── UnLuaIntelliSenseCommandlet.cpp │ │ ├── UnLuaEditor.cpp │ │ ├── UnLuaEditorCommands.cpp │ │ ├── UnLuaEditorCommands.h │ │ ├── UnLuaEditorCore.cpp │ │ ├── UnLuaEditorStyle.cpp │ │ └── UnLuaEditorStyle.h │ └── UnLuaEditor.Build.cs └── UnLuaIntelliSense │ ├── Private │ └── UnLuaIntelliSense.cpp │ └── UnLuaIntelliSense.Build.cs └── UnLua.uplugin /README.md: -------------------------------------------------------------------------------- 1 | # UnLuaWithLibs 2 | ##UnLua常用库集成 3 | 4 | 基于Unlua插件,在插件层级加了一些自己用到的第三方lua库的扩展。
5 | UnLua: https://github.com/Tencent/UnLua 6 | 7 | ## LuaSocket 8 | 9 | 集成方法参考BlueLua,这个库是基本直接copy过来的,如有需要接LuaPanda的同学也可自行从该工程添加
10 | BlueLua: https://github.com/jashking/Bluelua 11 | 12 | ## LuaCrypt 13 | 14 | 字符串的一些加密解密函数库 15 | 16 | ## LPeg 17 | 18 | 模式匹配库。 19 | 20 | ## Sproto 21 | 22 | skynet的定制协议 23 | 24 | ## Lua-Cjson 25 | 26 | 可以对json进行encode和decode 27 | 28 | ## 如何使用 29 | 30 | 直接将Unlua文件夹拷贝到plugin目录下,重新编译你的工程
31 | 32 | ##添加库(以lpeg库为例)
33 | 1.在Plugins\UnLua\Source\ThirdParty\目录下新建文件夹LibLpeg
34 | 2.从已有库复制相对应的.h、.cpp、.build.cs文件到LibLpeg目录下,并将文件名修改为LibLpeg.h、LibLpeg.cpp、LibLpeg.build.cs
35 | 3.文件夹内放入Lpeg库源码,并将上一步的三个文件内的模块名替换成LibLpeg相关
36 | 4.在UnLua.uplugin文件中添加新增模块的相应配置,在UnLua.Build.cs添加模块名LibLpeg
37 | 5.extern "C" {}内添加源码头文件,在FLibLpegModule::SetupLibLpeg函数中注册函数
38 | ```lua 39 | lua_pushcfunction(L, luaopen_lpeg); 40 | lua_setfield(L, -2, "lpeg"); 41 | ``` 42 | 6.删掉项目的sln文件,重新生成编译,根据报错内容对源码进行相应修改
43 | 7.LuaContext.cpp的CreateState方法添加注册 44 | ```cpp 45 | //lualpeg 46 | if (FLibLpegModule::IsAvailable()) 47 | { 48 | FLibLpegModule::Get().SetupLibLpeg(L); 49 | lua_pushboolean(L, true); 50 | lua_setglobal(L, "SupportLpeg"); 51 | 52 | UE_LOG(LogUnLua, Log, TEXT("Lua state setup with LuaLpeg.")); 53 | } 54 | ``` 55 | 56 | ## 注意 57 | 58 | * 目前已添加多平台的支持 59 | * 这几个库的使用请查阅相关文档 60 | -------------------------------------------------------------------------------- /UnLua/Content/ActorComponentTemplate.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- DESCRIPTION 3 | -- 4 | -- @COMPANY ** 5 | -- @AUTHOR ** 6 | -- @DATE ${date} ${time} 7 | -- 8 | 9 | require "UnLua" 10 | 11 | local TemplateName = Class() 12 | 13 | --function TemplateName:Initialize(Initializer) 14 | --end 15 | 16 | --function TemplateName:ReceiveBeginPlay() 17 | --end 18 | 19 | --function TemplateName:ReceiveEndPlay() 20 | --end 21 | 22 | -- function TemplateName:ReceiveTick(DeltaSeconds) 23 | -- end 24 | 25 | return TemplateName 26 | -------------------------------------------------------------------------------- /UnLua/Content/ActorTemplate.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- DESCRIPTION 3 | -- 4 | -- @COMPANY ** 5 | -- @AUTHOR ** 6 | -- @DATE ${date} ${time} 7 | -- 8 | 9 | require "UnLua" 10 | 11 | local TemplateName = Class() 12 | 13 | --function TemplateName:Initialize(Initializer) 14 | --end 15 | 16 | --function TemplateName:UserConstructionScript() 17 | --end 18 | 19 | --function TemplateName:ReceiveBeginPlay() 20 | --end 21 | 22 | --function TemplateName:ReceiveEndPlay() 23 | --end 24 | 25 | -- function TemplateName:ReceiveTick(DeltaSeconds) 26 | -- end 27 | 28 | --function TemplateName:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser) 29 | --end 30 | 31 | --function TemplateName:ReceiveActorBeginOverlap(OtherActor) 32 | --end 33 | 34 | --function TemplateName:ReceiveActorEndOverlap(OtherActor) 35 | --end 36 | 37 | return TemplateName 38 | -------------------------------------------------------------------------------- /UnLua/Content/AnimInstanceTemplate.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- DESCRIPTION 3 | -- 4 | -- @COMPANY ** 5 | -- @AUTHOR ** 6 | -- @DATE ${date} ${time} 7 | -- 8 | 9 | require "UnLua" 10 | 11 | local TemplateName = Class() 12 | 13 | --function TemplateName:Initialize(Initializer) 14 | --end 15 | 16 | --function TemplateName:BlueprintInitializeAnimation() 17 | --end 18 | 19 | --function TemplateName:BlueprintBeginPlay() 20 | --end 21 | 22 | --function TemplateName:BlueprintUpdateAnimation(DeltaTimeX) 23 | --end 24 | 25 | -- function TemplateName:BlueprintPostEvaluateAnimation() 26 | -- end 27 | 28 | return TemplateName 29 | -------------------------------------------------------------------------------- /UnLua/Content/UnLua.lua: -------------------------------------------------------------------------------- 1 | local rawget = rawget 2 | local rawset = rawset 3 | local type = type 4 | local getmetatable = getmetatable 5 | local setmetatable = setmetatable 6 | local require = require 7 | local str_sub = string.sub 8 | 9 | local GetUProperty = GetUProperty 10 | local SetUProperty = SetUProperty 11 | local RegisterClass = RegisterClass 12 | local RegisterEnum = RegisterEnum 13 | local print = UEPrint 14 | 15 | _NotExist = _NotExist or {} 16 | local NotExist = _NotExist 17 | 18 | local function Index(t, k) 19 | local mt = getmetatable(t) 20 | local super = mt 21 | while super do 22 | local v = rawget(super, k) 23 | if v~= nil then 24 | if rawequal(v, NotExist) then 25 | return nil 26 | end 27 | rawset(t, k, v) 28 | return v 29 | end 30 | super = rawget(super, "Super") 31 | end 32 | local p = mt[k] 33 | 34 | if p ~= nil then 35 | if type(p) == "userdata" then 36 | return GetUProperty(t, p) 37 | elseif type(p) == "function" then 38 | rawset(t, k, p) 39 | elseif rawequal(p, NotExist) then 40 | return nil 41 | end 42 | else 43 | rawset(mt, k, NotExist) 44 | end 45 | return p 46 | end 47 | 48 | local function NewIndex(t, k, v) 49 | local mt = getmetatable(t) 50 | local p = mt[k] 51 | if type(p) == "userdata" then 52 | return SetUProperty(t, p, v) 53 | end 54 | rawset(t, k, v) 55 | end 56 | 57 | local function Class(super_name) 58 | local super_class = nil 59 | if super_name ~= nil then 60 | super_class = require(super_name) 61 | end 62 | 63 | local new_class = {} 64 | new_class.__index = Index 65 | new_class.__newindex = NewIndex 66 | new_class.Super = super_class 67 | 68 | return new_class 69 | end 70 | 71 | local function global_index(t, k) 72 | if type(k) == "string" then 73 | local s = str_sub(k, 1, 1) 74 | if s == "U" or s == "A" or s == "F" then 75 | RegisterClass(k) 76 | elseif s == "E" then 77 | RegisterEnum(k) 78 | end 79 | end 80 | return rawget(t, k) 81 | end 82 | 83 | if WITH_UE4_NAMESPACE then 84 | print("WITH_UE4_NAMESPACE==true"); 85 | else 86 | local global_mt = {} 87 | global_mt.__index = global_index 88 | setmetatable(_G, global_mt) 89 | UE4 = _G 90 | 91 | print("WITH_UE4_NAMESPACE==false"); 92 | end 93 | 94 | _G.print = print 95 | _G.Index = Index 96 | _G.NewIndex = NewIndex 97 | _G.Class = Class -------------------------------------------------------------------------------- /UnLua/Content/UserWidgetTemplate.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- DESCRIPTION 3 | -- 4 | -- @COMPANY ** 5 | -- @AUTHOR ** 6 | -- @DATE ${date} ${time} 7 | -- 8 | 9 | require "UnLua" 10 | 11 | local TemplateName = Class() 12 | 13 | --function TemplateName:Initialize(Initializer) 14 | --end 15 | 16 | --function TemplateName:PreConstruct(IsDesignTime) 17 | --end 18 | 19 | -- function TemplateName:Construct() 20 | -- end 21 | 22 | --function TemplateName:Tick(MyGeometry, InDeltaTime) 23 | --end 24 | 25 | return TemplateName 26 | -------------------------------------------------------------------------------- /UnLua/Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Resources/Icon128.png -------------------------------------------------------------------------------- /UnLua/Resources/icon_luatemplate_40x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Resources/icon_luatemplate_40x.png -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/LibCjson.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class LibCjson : ModuleRules 6 | { 7 | public LibCjson(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core" }); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { "Lua" }); 14 | 15 | bEnableShadowVariableWarnings = false; 16 | bEnableUndefinedIdentifierWarnings = false; 17 | 18 | PublicDefinitions.Add("WITH_LibCjson=1"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/LibCjson.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | #include "LibCjson.h" 3 | 4 | #include "lua.hpp" 5 | //#include "fpconv.h" 6 | //#include "strbuf.h" 7 | //#include "fpconv.h" 8 | 9 | extern "C" { 10 | //#include "fpconv.h" 11 | #include "lua_cjson.c" 12 | 13 | 14 | } 15 | 16 | IMPLEMENT_MODULE(FLibCjsonModule, LibCjson); 17 | 18 | void FLibCjsonModule::StartupModule() 19 | { 20 | 21 | } 22 | 23 | void FLibCjsonModule::ShutdownModule() 24 | { 25 | 26 | } 27 | 28 | void FLibCjsonModule::SetupLibCjson(lua_State* L) 29 | { 30 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 31 | luaL_requiref(L, "cjson", luaopen_cjson, 1); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/LibCjson.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | struct lua_State; 9 | 10 | class LIBCJSON_API FLibCjsonModule : public IModuleInterface 11 | { 12 | public: 13 | 14 | /** IModuleInterface implementation */ 15 | virtual void StartupModule() override; 16 | virtual void ShutdownModule() override; 17 | 18 | void SetupLibCjson(lua_State* L); 19 | 20 | static inline FLibCjsonModule& Get() 21 | { 22 | return FModuleManager::LoadModuleChecked("LibCjson"); 23 | } 24 | 25 | static inline bool IsAvailable() 26 | { 27 | return FModuleManager::Get().IsModuleLoaded("LibCjson"); 28 | } 29 | 30 | protected: 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/dtoa_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _DTOA_CONFIG_H 2 | #define _DTOA_CONFIG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale 9 | * aware conversion routines. */ 10 | #undef USE_LOCALE 11 | 12 | /* dtoa.c should not touch errno, Lua CJSON does not use it, and it 13 | * may not be threadsafe */ 14 | #define NO_ERRNO 15 | 16 | #define Long int32_t 17 | #define ULong uint32_t 18 | #define Llong int64_t 19 | #define ULLong uint64_t 20 | 21 | #ifdef IEEE_BIG_ENDIAN 22 | #define IEEE_MC68k 23 | #else 24 | #define IEEE_8087 25 | #endif 26 | 27 | #define MALLOC(n) xmalloc(n) 28 | 29 | static void *xmalloc(size_t size) 30 | { 31 | void *p; 32 | 33 | p = malloc(size); 34 | if (!p) { 35 | fprintf(stderr, "Out of memory"); 36 | abort(); 37 | } 38 | 39 | return p; 40 | } 41 | 42 | #ifdef MULTIPLE_THREADS 43 | 44 | /* Enable locking to support multi-threaded applications */ 45 | 46 | #include 47 | 48 | static pthread_mutex_t private_dtoa_lock[2] = { 49 | PTHREAD_MUTEX_INITIALIZER, 50 | PTHREAD_MUTEX_INITIALIZER 51 | }; 52 | 53 | #define ACQUIRE_DTOA_LOCK(n) do { \ 54 | int r = pthread_mutex_lock(&private_dtoa_lock[n]); \ 55 | if (r) { \ 56 | fprintf(stderr, "pthread_mutex_lock failed with %d\n", r); \ 57 | abort(); \ 58 | } \ 59 | } while (0) 60 | 61 | #define FREE_DTOA_LOCK(n) do { \ 62 | int r = pthread_mutex_unlock(&private_dtoa_lock[n]); \ 63 | if (r) { \ 64 | fprintf(stderr, "pthread_mutex_unlock failed with %d\n", r);\ 65 | abort(); \ 66 | } \ 67 | } while (0) 68 | 69 | #endif /* MULTIPLE_THREADS */ 70 | 71 | #endif /* _DTOA_CONFIG_H */ 72 | 73 | /* vi:ai et sw=4 ts=4: 74 | */ 75 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | #define FPCONV_G_FMT_BUFSIZE 32 8 | //使用内部的转换机制 9 | #define USE_INTERNAL_FPCONV 10 | //暴露cjson 为lua的全局对象使用就像使用os.clock()直接使用 11 | #define ENABLE_CJSON_GLOBAL 12 | //将inline 冲定义为 __inline 13 | #define inline __inline 14 | #ifdef USE_INTERNAL_FPCONV 15 | static inline void fpconv_init() 16 | { 17 | /* Do nothing - not required */ 18 | } 19 | #else 20 | extern inline void fpconv_init(); 21 | #endif 22 | 23 | extern int fpconv_g_fmt(char*, double, int); 24 | extern double fpconv_strtod(const char*, char**); 25 | 26 | /* vi:ai et sw=4 ts=4: 27 | */ -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/g_fmt.c: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * The author of this software is David M. Gay. 4 | * 5 | * Copyright (c) 1991, 1996 by Lucent Technologies. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose without fee is hereby granted, provided that this entire notice 9 | * is included in all copies of any software which is or includes a copy 10 | * or modification of this software and in all copies of the supporting 11 | * documentation for such software. 12 | * 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 15 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 16 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | * 18 | ***************************************************************/ 19 | 20 | /* g_fmt(buf,x) stores the closest decimal approximation to x in buf; 21 | * it suffices to declare buf 22 | * char buf[32]; 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | extern char *dtoa(double, int, int, int *, int *, char **); 29 | extern int g_fmt(char *, double, int); 30 | extern void freedtoa(char*); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | int 36 | fpconv_g_fmt(char *b, double x, int precision) 37 | { 38 | register int i, k; 39 | register char *s; 40 | int decpt, j, sign; 41 | char *b0, *s0, *se; 42 | 43 | b0 = b; 44 | #ifdef IGNORE_ZERO_SIGN 45 | if (!x) { 46 | *b++ = '0'; 47 | *b = 0; 48 | goto done; 49 | } 50 | #endif 51 | s = s0 = dtoa(x, 2, precision, &decpt, &sign, &se); 52 | if (sign) 53 | *b++ = '-'; 54 | if (decpt == 9999) /* Infinity or Nan */ { 55 | while((*b++ = *s++)); 56 | /* "b" is used to calculate the return length. Decrement to exclude the 57 | * Null terminator from the length */ 58 | b--; 59 | goto done0; 60 | } 61 | if (decpt <= -4 || decpt > precision) { 62 | *b++ = *s++; 63 | if (*s) { 64 | *b++ = '.'; 65 | while((*b = *s++)) 66 | b++; 67 | } 68 | *b++ = 'e'; 69 | /* sprintf(b, "%+.2d", decpt - 1); */ 70 | if (--decpt < 0) { 71 | *b++ = '-'; 72 | decpt = -decpt; 73 | } 74 | else 75 | *b++ = '+'; 76 | for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); 77 | for(;;) { 78 | i = decpt / k; 79 | *b++ = i + '0'; 80 | if (--j <= 0) 81 | break; 82 | decpt -= i*k; 83 | decpt *= 10; 84 | } 85 | *b = 0; 86 | } 87 | else if (decpt <= 0) { 88 | *b++ = '0'; 89 | *b++ = '.'; 90 | for(; decpt < 0; decpt++) 91 | *b++ = '0'; 92 | while((*b++ = *s++)); 93 | b--; 94 | } 95 | else { 96 | while((*b = *s++)) { 97 | b++; 98 | if (--decpt == 0 && *s) 99 | *b++ = '.'; 100 | } 101 | for(; decpt > 0; decpt--) 102 | *b++ = '0'; 103 | *b = 0; 104 | } 105 | done0: 106 | freedtoa(s0); 107 | #ifdef IGNORE_ZERO_SIGN 108 | done: 109 | #endif 110 | return b - b0; 111 | } 112 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/lua/json2lua.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | -- usage: json2lua.lua [json_file] 4 | -- 5 | -- Eg: 6 | -- echo '[ "testing" ]' | ./json2lua.lua 7 | -- ./json2lua.lua test.json 8 | 9 | local json = require "cjson" 10 | local util = require "cjson.util" 11 | 12 | local json_text = util.file_load(arg[1]) 13 | local t = json.decode(json_text) 14 | print(util.serialise_value(t)) 15 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibCjson/lua/lua2json.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | -- usage: lua2json.lua [lua_file] 4 | -- 5 | -- Eg: 6 | -- echo '{ "testing" }' | ./lua2json.lua 7 | -- ./lua2json.lua test.lua 8 | 9 | local json = require "cjson" 10 | local util = require "cjson.util" 11 | 12 | local env = { 13 | json = { null = json.null }, 14 | null = json.null 15 | } 16 | 17 | local t = util.run_script("data = " .. util.file_load(arg[1]), env) 18 | print(json.encode(t.data)) 19 | 20 | -- vi:ai et sw=4 ts=4: 21 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/HISTORY: -------------------------------------------------------------------------------- 1 | HISTORY for LPeg 1.0 2 | 3 | * Changes from version 0.12 to 1.0 4 | --------------------------------- 5 | + group "names" can be any Lua value 6 | + some bugs fixed 7 | + other small improvements 8 | 9 | * Changes from version 0.11 to 0.12 10 | --------------------------------- 11 | + no "unsigned short" limit for pattern sizes 12 | + mathtime captures considered nullable 13 | + some bugs fixed 14 | 15 | * Changes from version 0.10 to 0.11 16 | ------------------------------- 17 | + complete reimplementation of the code generator 18 | + new syntax for table captures 19 | + new functions in module 're' 20 | + other small improvements 21 | 22 | * Changes from version 0.9 to 0.10 23 | ------------------------------- 24 | + backtrack stack has configurable size 25 | + better error messages 26 | + Notation for non-terminals in 're' back to A instead o 27 | + experimental look-behind pattern 28 | + support for external extensions 29 | + works with Lua 5.2 30 | + consumes less C stack 31 | 32 | - "and" predicates do not keep captures 33 | 34 | * Changes from version 0.8 to 0.9 35 | ------------------------------- 36 | + The accumulator capture was replaced by a fold capture; 37 | programs that used the old 'lpeg.Ca' will need small changes. 38 | + Some support for character classes from old C locales. 39 | + A new named-group capture. 40 | 41 | * Changes from version 0.7 to 0.8 42 | ------------------------------- 43 | + New "match-time" capture. 44 | + New "argument capture" that allows passing arguments into the pattern. 45 | + Better documentation for 're'. 46 | + Several small improvements for 're'. 47 | + The 're' module has an incompatibility with previous versions: 48 | now, any use of a non-terminal must be enclosed in angle brackets 49 | (like ). 50 | 51 | * Changes from version 0.6 to 0.7 52 | ------------------------------- 53 | + Several improvements in module 're': 54 | - better documentation; 55 | - support for most captures (all but accumulator); 56 | - limited repetitions p{n,m}. 57 | + Small improvements in efficiency. 58 | + Several small bugs corrected (special thanks to Hans Hagen 59 | and Taco Hoekwater). 60 | 61 | * Changes from version 0.5 to 0.6 62 | ------------------------------- 63 | + Support for non-numeric indices in grammars. 64 | + Some bug fixes (thanks to the luatex team). 65 | + Some new optimizations; (thanks to Mike Pall). 66 | + A new page layout (thanks to Andre Carregal). 67 | + Minimal documentation for module 're'. 68 | 69 | * Changes from version 0.4 to 0.5 70 | ------------------------------- 71 | + Several optimizations. 72 | + lpeg.P now accepts booleans. 73 | + Some new examples. 74 | + A proper license. 75 | + Several small improvements. 76 | 77 | * Changes from version 0.3 to 0.4 78 | ------------------------------- 79 | + Static check for loops in repetitions and grammars. 80 | + Removed label option in captures. 81 | + The implementation of captures uses less memory. 82 | 83 | * Changes from version 0.2 to 0.3 84 | ------------------------------- 85 | + User-defined patterns in Lua. 86 | + Several new captures. 87 | 88 | * Changes from version 0.1 to 0.2 89 | ------------------------------- 90 | + Several small corrections. 91 | + Handles embedded zeros like any other character. 92 | + Capture "name" can be any Lua value. 93 | + Unlimited number of captures. 94 | + Match gets an optional initial position. 95 | 96 | (end of HISTORY) 97 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/LibLpeg.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class LibLpeg : ModuleRules 6 | { 7 | public LibLpeg(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core" }); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { "Lua" }); 14 | 15 | bEnableShadowVariableWarnings = false; 16 | bEnableUndefinedIdentifierWarnings = false; 17 | 18 | PublicDefinitions.Add("WITH_LibLpeg=1"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/LibLpeg.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | #include "LibLpeg.h" 3 | 4 | #include "lua.hpp" 5 | 6 | extern "C" { 7 | 8 | #include "lpcap.h" 9 | #include "lpcode.h" 10 | #include "lpprint.h" 11 | #include "lptree.h" 12 | #include "lptypes.h" 13 | #include "lpvm.h" 14 | 15 | } 16 | 17 | IMPLEMENT_MODULE(FLibLpegModule, LibLpeg); 18 | 19 | void FLibLpegModule::StartupModule() 20 | { 21 | 22 | } 23 | 24 | void FLibLpegModule::ShutdownModule() 25 | { 26 | 27 | } 28 | 29 | void FLibLpegModule::SetupLibLpeg(lua_State* L) 30 | { 31 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 32 | 33 | luaL_requiref(L, "lpeg", luaopen_lpeg, 1); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/LibLpeg.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | struct lua_State; 9 | 10 | class LIBLPEG_API FLibLpegModule : public IModuleInterface 11 | { 12 | public: 13 | 14 | /** IModuleInterface implementation */ 15 | virtual void StartupModule() override; 16 | virtual void ShutdownModule() override; 17 | 18 | void SetupLibLpeg(lua_State* L); 19 | 20 | static inline FLibLpegModule& Get() 21 | { 22 | return FModuleManager::LoadModuleChecked("LibLpeg"); 23 | } 24 | 25 | static inline bool IsAvailable() 26 | { 27 | return FModuleManager::Get().IsModuleLoaded("LibLpeg"); 28 | } 29 | 30 | protected: 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lpcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcap.h,v 1.3 2016/09/13 17:45:58 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcap_h) 6 | #define lpcap_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* kinds of captures */ 13 | typedef enum CapKind { 14 | Cclose, /* not used in trees */ 15 | Cposition, 16 | Cconst, /* ktable[key] is Lua constant */ 17 | Cbackref, /* ktable[key] is "name" of group to get capture */ 18 | Carg, /* 'key' is arg's number */ 19 | Csimple, /* next node is pattern */ 20 | Ctable, /* next node is pattern */ 21 | Cfunction, /* ktable[key] is function; next node is pattern */ 22 | Cquery, /* ktable[key] is table; next node is pattern */ 23 | Cstring, /* ktable[key] is string; next node is pattern */ 24 | Cnum, /* numbered capture; 'key' is number of value to return */ 25 | Csubst, /* substitution capture; next node is pattern */ 26 | Cfold, /* ktable[key] is function; next node is pattern */ 27 | Cruntime, /* not used in trees (is uses another type for tree) */ 28 | Cgroup /* ktable[key] is group's "name" */ 29 | } CapKind; 30 | 31 | 32 | typedef struct Capture { 33 | const char *s; /* subject position */ 34 | unsigned short idx; /* extra info (group name, arg index, etc.) */ 35 | byte kind; /* kind of capture */ 36 | byte siz; /* size of full capture + 1 (0 = not a full capture) */ 37 | } Capture; 38 | 39 | 40 | typedef struct CapState { 41 | Capture *cap; /* current capture */ 42 | Capture *ocap; /* (original) capture list */ 43 | lua_State *L; 44 | int ptop; /* index of last argument to 'match' */ 45 | const char *s; /* original string */ 46 | int valuecached; /* value stored in cache slot */ 47 | } CapState; 48 | 49 | 50 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); 51 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop); 52 | int finddyncap (Capture *cap, Capture *last); 53 | 54 | #endif 55 | 56 | 57 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lpcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcode.h,v 1.8 2016/09/15 17:46:13 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcode_h) 6 | #define lpcode_h 7 | 8 | #include "lua.h" 9 | 10 | #include "lptypes.h" 11 | #include "lptree.h" 12 | #include "lpvm.h" 13 | 14 | int tocharset (TTree *tree, Charset *cs); 15 | int checkaux (TTree *tree, int pred); 16 | int fixedlen (TTree *tree); 17 | int hascaptures (TTree *tree); 18 | int lp_gc (lua_State *L); 19 | Instruction *compile (lua_State *L, Pattern *p); 20 | void realloccode (lua_State *L, Pattern *p, int nsize); 21 | int sizei (const Instruction *i); 22 | 23 | 24 | #define PEnullable 0 25 | #define PEnofail 1 26 | 27 | /* 28 | ** nofail(t) implies that 't' cannot fail with any input 29 | */ 30 | #define nofail(t) checkaux(t, PEnofail) 31 | 32 | /* 33 | ** (not nullable(t)) implies 't' cannot match without consuming 34 | ** something 35 | */ 36 | #define nullable(t) checkaux(t, PEnullable) 37 | 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lpeg-128.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/LibLpeg/lpeg-128.gif -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lpprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $ 3 | */ 4 | 5 | 6 | #if !defined(lpprint_h) 7 | #define lpprint_h 8 | 9 | 10 | #include "lptree.h" 11 | #include "lpvm.h" 12 | 13 | 14 | #if defined(LPEG_DEBUG) 15 | 16 | void printpatt (Instruction *p, int n); 17 | void printtree (TTree *tree, int ident); 18 | void printktable (lua_State *L, int idx); 19 | void printcharset (const byte *st); 20 | void printcaplist (Capture *cap, Capture *limit); 21 | void printinst (const Instruction *op, const Instruction *p); 22 | 23 | #else 24 | 25 | #define printktable(L,idx) \ 26 | luaL_error(L, "function only implemented in debug mode") 27 | #define printtree(tree,i) \ 28 | luaL_error(L, "function only implemented in debug mode") 29 | #define printpatt(p,n) \ 30 | luaL_error(L, "function only implemented in debug mode") 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lptree.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lptree_h) 6 | #define lptree_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | /* 12 | ** types of trees 13 | */ 14 | typedef enum TLibLpegTag { 15 | TLibLpegChar = 0, /* 'n' = char */ 16 | TLibLpegSet, /* the set is stored in next CHARSETSIZE bytes */ 17 | TLibLpegAny, 18 | TLibLpegTrue, 19 | TLibLpegFalse, 20 | TLibLpegRep, /* 'sib1'* */ 21 | TLibLpegSeq, /* 'sib1' 'sib2' */ 22 | TLibLpegChoice, /* 'sib1' / 'sib2' */ 23 | TLibLpegNot, /* !'sib1' */ 24 | TLibLpegAnd, /* &'sib1' */ 25 | TLibLpegCall, /* ktable[key] is rule's key; 'sib2' is rule being called */ 26 | TLibLpegOpenCall, /* ktable[key] is rule's key */ 27 | TLibLpegRule, /* ktable[key] is rule's key (but key == 0 for unused rules); 28 | 'sib1' is rule's pattern; 29 | 'sib2' is next rule; 'cap' is rule's sequential number */ 30 | TLibLpegGrammar, /* 'sib1' is initial (and first) rule */ 31 | TLibLpegBehind, /* 'sib1' is pattern, 'n' is how much to go back */ 32 | TLibLpegCapture, /* captures: 'cap' is kind of capture (enum 'CapKind'); 33 | ktable[key] is Lua value associated with capture; 34 | 'sib1' is capture body */ 35 | TLibLpegRunTime /* run-time capture: 'key' is Lua function; 36 | 'sib1' is capture body */ 37 | } TLibLpegTag; 38 | 39 | 40 | /* 41 | ** Tree trees 42 | ** The first child of a tree (if there is one) is immediately after 43 | ** the tree. A reference to a second child (ps) is its position 44 | ** relative to the position of the tree itself. 45 | */ 46 | typedef struct TTree { 47 | byte tag; 48 | byte cap; /* kind of capture (if it is a capture) */ 49 | unsigned short key; /* key in ktable for Lua data (0 if no key) */ 50 | union { 51 | int ps; /* occasional second child */ 52 | int n; /* occasional counter */ 53 | } u; 54 | } TTree; 55 | 56 | 57 | /* 58 | ** A complete pattern has its tree plus, if already compiled, 59 | ** its corresponding code 60 | */ 61 | typedef struct Pattern { 62 | union Instruction *code; 63 | int codesize; 64 | TTree tree[1]; 65 | } Pattern; 66 | 67 | 68 | /* number of children for each tree */ 69 | extern const byte numsiblings[]; 70 | extern int luaopen_lpeg(lua_State *L); 71 | /* access to children */ 72 | #define sib1(t) ((t) + 1) 73 | #define sib2(t) ((t) + (t)->u.ps) 74 | 75 | 76 | 77 | 78 | 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lptypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lptypes.h,v 1.16 2017/01/13 13:33:17 roberto Exp $ 3 | ** LPeg - PEG pattern matching for Lua 4 | ** Copyright 2007-2017, Lua.org & PUC-Rio (see 'lpeg.html' for license) 5 | ** written by Roberto Ierusalimschy 6 | */ 7 | 8 | #if !defined(lptypes_h) 9 | #define lptypes_h 10 | 11 | #include 12 | #include 13 | 14 | #include "lua.h" 15 | 16 | 17 | #define VERSION "1.0.1" 18 | 19 | 20 | #define PATTERN_T "lpeg-pattern" 21 | #define MAXSTACKIDX "lpeg-maxstack" 22 | 23 | 24 | /* 25 | ** compatibility with Lua 5.1 26 | */ 27 | #if (LUA_VERSION_NUM == 501) 28 | 29 | #define lp_equal lua_equal 30 | 31 | #define lua_getuservalue lua_getfenv 32 | #define lua_setuservalue lua_setfenv 33 | 34 | #define lua_rawlen lua_objlen 35 | 36 | #define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f) 37 | #define luaL_newlib(L,f) luaL_register(L,"lpeg",f) 38 | 39 | #endif 40 | 41 | 42 | #if !defined(lp_equal) 43 | #define lp_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) 44 | #endif 45 | 46 | 47 | /* default maximum size for call/backtrack stack */ 48 | #if !defined(MAXBACK) 49 | #define MAXBACK 400 50 | #endif 51 | 52 | 53 | /* maximum number of rules in a grammar (limited by 'unsigned char') */ 54 | #if !defined(MAXRULES) 55 | #define MAXRULES 250 56 | #endif 57 | 58 | 59 | 60 | /* initial size for capture's list */ 61 | #define INITCAPSIZE 32 62 | 63 | 64 | /* index, on Lua stack, for subject */ 65 | #define SUBJIDX 2 66 | 67 | /* number of fixed arguments to 'match' (before capture arguments) */ 68 | #define FIXEDARGS 3 69 | 70 | /* index, on Lua stack, for capture list */ 71 | #define caplistidx(ptop) ((ptop) + 2) 72 | 73 | /* index, on Lua stack, for pattern's ktable */ 74 | #define ktableidx(ptop) ((ptop) + 3) 75 | 76 | /* index, on Lua stack, for backtracking stack */ 77 | #define stackidx(ptop) ((ptop) + 4) 78 | 79 | 80 | 81 | typedef unsigned char byte; 82 | 83 | 84 | #define BITSPERCHAR 8 85 | 86 | #define CHARSETSIZE ((UCHAR_MAX/BITSPERCHAR) + 1) 87 | 88 | 89 | 90 | typedef struct Charset { 91 | byte cs[CHARSETSIZE]; 92 | } Charset; 93 | 94 | 95 | 96 | #define loopset(v,b) { int v; for (v = 0; v < CHARSETSIZE; v++) {b;} } 97 | 98 | /* access to charset */ 99 | #define treebuffer(t) ((byte *)((t) + 1)) 100 | 101 | /* number of slots needed for 'n' bytes */ 102 | #define bytes2slots(n) (((n) - 1) / sizeof(TTree) + 1) 103 | 104 | /* set 'b' bit in charset 'cs' */ 105 | #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) 106 | 107 | 108 | /* 109 | ** in capture instructions, 'kind' of capture and its offset are 110 | ** packed in field 'aux', 4 bits for each 111 | */ 112 | #define getkind(op) ((op)->i.aux & 0xF) 113 | #define getoff(op) (((op)->i.aux >> 4) & 0xF) 114 | #define joinkindoff(k,o) ((k) | ((o) << 4)) 115 | 116 | #define MAXOFF 0xF 117 | #define MAXAUX 0xFF 118 | 119 | 120 | /* maximum number of bytes to look behind */ 121 | #define MAXBEHIND MAXAUX 122 | 123 | 124 | /* maximum size (in elements) for a pattern */ 125 | #define MAXPATTSIZE (SHRT_MAX - 10) 126 | 127 | 128 | /* size (in elements) for an instruction plus extra l bytes */ 129 | #define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1) 130 | 131 | 132 | /* size (in elements) for a ISet instruction */ 133 | #define CHARSETINSTSIZE instsize(CHARSETSIZE) 134 | 135 | /* size (in elements) for a IFunc instruction */ 136 | #define funcinstsize(p) ((p)->i.aux + 2) 137 | 138 | 139 | 140 | #define testchar(st,c) (((int)(st)[((c) >> 3)] & (1 << ((c) & 7)))) 141 | 142 | 143 | #endif 144 | 145 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/lpvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpvm.h,v 1.3 2014/02/21 13:06:41 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpvm_h) 6 | #define lpvm_h 7 | 8 | #include "lpcap.h" 9 | 10 | 11 | /* Virtual Machine's instructions */ 12 | typedef enum Opcode { 13 | IAny, /* if no char, fail */ 14 | IChar, /* if char != aux, fail */ 15 | ISet, /* if char not in buff, fail */ 16 | ITestAny, /* in no char, jump to 'offset' */ 17 | ITestChar, /* if char != aux, jump to 'offset' */ 18 | ITestSet, /* if char not in buff, jump to 'offset' */ 19 | ISpan, /* read a span of chars in buff */ 20 | IBehind, /* walk back 'aux' characters (fail if not possible) */ 21 | IRet, /* return from a rule */ 22 | IEnd, /* end of pattern */ 23 | IChoice, /* stack a choice; next fail will jump to 'offset' */ 24 | IJmp, /* jump to 'offset' */ 25 | ICall, /* call rule at 'offset' */ 26 | IOpenCall, /* call rule number 'key' (must be closed to a ICall) */ 27 | ICommit, /* pop choice and jump to 'offset' */ 28 | IPartialCommit, /* update top choice to current position and jump */ 29 | IBackCommit, /* "fails" but jump to its own 'offset' */ 30 | IFailTwice, /* pop one choice and then fail */ 31 | IFail, /* go back to saved state on choice and jump to saved offset */ 32 | IGiveup, /* internal use */ 33 | IFullCapture, /* complete capture of last 'off' chars */ 34 | IOpenCapture, /* start a capture */ 35 | ICloseCapture, 36 | ICloseRunTime 37 | } Opcode; 38 | 39 | 40 | 41 | typedef union Instruction { 42 | struct Inst { 43 | byte code; 44 | byte aux; 45 | short key; 46 | } i; 47 | int offset; 48 | byte buff[1]; 49 | } Instruction; 50 | 51 | 52 | void printpatt (Instruction *p, int n); 53 | const char *match (lua_State *L, const char *o, const char *s, const char *e, 54 | Instruction *op, Capture *capture, int ptop); 55 | 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLpeg/makefile: -------------------------------------------------------------------------------- 1 | LIBNAME = lpeg 2 | LUADIR = ../lua/ 3 | 4 | COPT = -O2 5 | # COPT = -DLPEG_DEBUG -g 6 | 7 | CWARNS = -Wall -Wextra -pedantic \ 8 | -Waggregate-return \ 9 | -Wcast-align \ 10 | -Wcast-qual \ 11 | -Wdisabled-optimization \ 12 | -Wpointer-arith \ 13 | -Wshadow \ 14 | -Wsign-compare \ 15 | -Wundef \ 16 | -Wwrite-strings \ 17 | -Wbad-function-cast \ 18 | -Wdeclaration-after-statement \ 19 | -Wmissing-prototypes \ 20 | -Wnested-externs \ 21 | -Wstrict-prototypes \ 22 | # -Wunreachable-code \ 23 | 24 | 25 | CFLAGS = $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC 26 | CC = gcc 27 | 28 | FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o 29 | 30 | # For Linux 31 | linux: 32 | make lpeg.so "DLLFLAGS = -shared -fPIC" 33 | 34 | # For Mac OS 35 | macosx: 36 | make lpeg.so "DLLFLAGS = -bundle -undefined dynamic_lookup" 37 | 38 | lpeg.so: $(FILES) 39 | env $(CC) $(DLLFLAGS) $(FILES) -o lpeg.so 40 | 41 | $(FILES): makefile 42 | 43 | test: test.lua re.lua lpeg.so 44 | ./test.lua 45 | 46 | clean: 47 | rm -f $(FILES) lpeg.so 48 | 49 | 50 | lpcap.o: lpcap.c lpcap.h lptypes.h 51 | lpcode.o: lpcode.c lptypes.h lpcode.h lptree.h lpvm.h lpcap.h 52 | lpprint.o: lpprint.c lptypes.h lpprint.h lptree.h lpvm.h lpcap.h 53 | lptree.o: lptree.c lptypes.h lpcap.h lpcode.h lptree.h lpvm.h lpprint.h 54 | lpvm.o: lpvm.c lpcap.h lptypes.h lpvm.h lpprint.h lptree.h 55 | 56 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuacrypt/LibLuacrypt.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class LibLuacrypt : ModuleRules 6 | { 7 | public LibLuacrypt(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core" }); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { "Lua" }); 14 | 15 | bEnableShadowVariableWarnings = false; 16 | bEnableUndefinedIdentifierWarnings = false; 17 | 18 | PublicDefinitions.Add("WITH_LibLuacrypt=1"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuacrypt/LibLuacrypt.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | #include "LibLuacrypt.h" 3 | 4 | #include "lua.hpp" 5 | #include "lsha1.c" 6 | #include "lua-crypt.c" 7 | 8 | extern "C" { 9 | 10 | } 11 | 12 | IMPLEMENT_MODULE(FLibLuacryptModule, LibLuacrypt); 13 | 14 | void FLibLuacryptModule::StartupModule() 15 | { 16 | 17 | } 18 | 19 | void FLibLuacryptModule::ShutdownModule() 20 | { 21 | 22 | } 23 | 24 | void FLibLuacryptModule::SetupLuacrypt(lua_State* L) 25 | { 26 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 27 | 28 | luaL_requiref(L, "crypt", luaopen_crypt, 1); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuacrypt/LibLuacrypt.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | struct lua_State; 9 | 10 | class LIBLUACRYPT_API FLibLuacryptModule : public IModuleInterface 11 | { 12 | public: 13 | 14 | /** IModuleInterface implementation */ 15 | virtual void StartupModule() override; 16 | virtual void ShutdownModule() override; 17 | 18 | void SetupLuacrypt(lua_State* L); 19 | 20 | static inline FLibLuacryptModule& Get() 21 | { 22 | return FModuleManager::LoadModuleChecked("LibLuacrypt"); 23 | } 24 | 25 | static inline bool IsAvailable() 26 | { 27 | return FModuleManager::Get().IsModuleLoaded("LibLuacrypt"); 28 | } 29 | 30 | protected: 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/LibLuasocket.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class LibLuasocket : ModuleRules 6 | { 7 | public LibLuasocket(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core" }); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { "Lua" }); 14 | 15 | bEnableShadowVariableWarnings = false; 16 | bEnableUndefinedIdentifierWarnings = false; 17 | 18 | PublicDefinitions.Add("WITH_LIBLUASOCKET=1"); 19 | 20 | if (Target.Configuration == UnrealTargetConfiguration.Debug || 21 | Target.Configuration == UnrealTargetConfiguration.DebugGame) 22 | { 23 | PrivateDefinitions.Add("LUASOCKET_DEBUG"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/LibLuasocket.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "LibLuasocket.h" 4 | 5 | #include "lua.hpp" 6 | 7 | extern "C" { 8 | #include "luasocket.h" 9 | #include "mime.h" 10 | } 11 | 12 | IMPLEMENT_MODULE(FLibLuasocketModule, LibLuasocket); 13 | 14 | void FLibLuasocketModule::StartupModule() 15 | { 16 | 17 | } 18 | 19 | void FLibLuasocketModule::ShutdownModule() 20 | { 21 | 22 | } 23 | 24 | void FLibLuasocketModule::SetupLuasocket(struct lua_State* L) 25 | { 26 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 27 | 28 | luaL_requiref(L, "socket.core", luaopen_socket_core, 1); 29 | luaL_requiref(L, "mime.core", luaopen_mime_core, 1); 30 | luaL_requiref(L, "socket", &FLibLuasocketModule::OpenLuaSocketSocket, 1); 31 | luaL_requiref(L, "ltn12", &FLibLuasocketModule::OpenLuaSocketLtn12, 1); 32 | luaL_requiref(L, "mime", &FLibLuasocketModule::OpenLuaSocketMime, 1); 33 | 34 | luaL_requiref(L, "socket.url", &FLibLuasocketModule::OpenLuaSocketUrl, 1); 35 | luaL_requiref(L, "socket.tp", &FLibLuasocketModule::OpenLuaSocketTp, 1); 36 | luaL_requiref(L, "socket.ftp", &FLibLuasocketModule::OpenLuaSocketFtp, 1); 37 | luaL_requiref(L, "socket.headers", &FLibLuasocketModule::OpenLuaSocketHeaders, 1); 38 | luaL_requiref(L, "socket.http", &FLibLuasocketModule::OpenLuaSocketHttp, 1); 39 | luaL_requiref(L, "mbox", &FLibLuasocketModule::OpenLuaSocketMbox, 1); 40 | luaL_requiref(L, "socket.smtp", &FLibLuasocketModule::OpenLuaSocketSmtp, 1); 41 | lua_pop(L, 1); 42 | } 43 | 44 | int FLibLuasocketModule::OpenLuaSocketFtp(lua_State* L) 45 | { 46 | static const auto RawLua = 47 | #include "ftp.lua.inc" 48 | 49 | luaL_dostring(L, RawLua); 50 | return 1; 51 | } 52 | 53 | int FLibLuasocketModule::OpenLuaSocketHeaders(lua_State* L) 54 | { 55 | static const auto RawLua = 56 | #include "headers.lua.inc" 57 | 58 | luaL_dostring(L, RawLua); 59 | return 1; 60 | } 61 | 62 | int FLibLuasocketModule::OpenLuaSocketHttp(lua_State* L) 63 | { 64 | static const auto RawLua = 65 | #include "http.lua.inc" 66 | 67 | luaL_dostring(L, RawLua); 68 | return 1; 69 | } 70 | 71 | int FLibLuasocketModule::OpenLuaSocketLtn12(lua_State* L) 72 | { 73 | static const auto RawLua = 74 | #include "ltn12.lua.inc" 75 | 76 | luaL_dostring(L, RawLua); 77 | return 1; 78 | } 79 | 80 | int FLibLuasocketModule::OpenLuaSocketMbox(lua_State* L) 81 | { 82 | static const auto RawLua = 83 | #include "mbox.lua.inc" 84 | 85 | luaL_dostring(L, RawLua); 86 | return 1; 87 | } 88 | 89 | int FLibLuasocketModule::OpenLuaSocketMime(lua_State* L) 90 | { 91 | static const auto RawLua = 92 | #include "mime.lua.inc" 93 | 94 | luaL_dostring(L, RawLua); 95 | return 1; 96 | } 97 | 98 | int FLibLuasocketModule::OpenLuaSocketSmtp(lua_State* L) 99 | { 100 | static const auto RawLua = 101 | #include "smtp.lua.inc" 102 | 103 | luaL_dostring(L, RawLua); 104 | return 1; 105 | } 106 | 107 | int FLibLuasocketModule::OpenLuaSocketSocket(lua_State* L) 108 | { 109 | static const auto RawLua = 110 | #include "socket.lua.inc" 111 | 112 | luaL_dostring(L, RawLua); 113 | return 1; 114 | } 115 | 116 | int FLibLuasocketModule::OpenLuaSocketTp(lua_State* L) 117 | { 118 | static const auto RawLua = 119 | #include "tp.lua.inc" 120 | 121 | luaL_dostring(L, RawLua); 122 | return 1; 123 | } 124 | 125 | int FLibLuasocketModule::OpenLuaSocketUrl(lua_State* L) 126 | { 127 | static const auto RawLua = 128 | #include "url.lua.inc" 129 | 130 | luaL_dostring(L, RawLua); 131 | return 1; 132 | } 133 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/LibLuasocket.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | struct lua_State; 9 | 10 | class LIBLUASOCKET_API FLibLuasocketModule : public IModuleInterface 11 | { 12 | public: 13 | 14 | /** IModuleInterface implementation */ 15 | virtual void StartupModule() override; 16 | virtual void ShutdownModule() override; 17 | 18 | void SetupLuasocket(lua_State* L); 19 | 20 | static inline FLibLuasocketModule& Get() 21 | { 22 | return FModuleManager::LoadModuleChecked("LibLuasocket"); 23 | } 24 | 25 | static inline bool IsAvailable() 26 | { 27 | return FModuleManager::Get().IsModuleLoaded("LibLuasocket"); 28 | } 29 | 30 | protected: 31 | static int OpenLuaSocketFtp(lua_State* L); 32 | static int OpenLuaSocketHeaders(lua_State* L); 33 | static int OpenLuaSocketHttp(lua_State* L); 34 | static int OpenLuaSocketLtn12(lua_State* L); 35 | static int OpenLuaSocketMbox(lua_State* L); 36 | static int OpenLuaSocketMime(lua_State* L); 37 | static int OpenLuaSocketSmtp(lua_State* L); 38 | static int OpenLuaSocketSocket(lua_State* L); 39 | static int OpenLuaSocketTp(lua_State* L); 40 | static int OpenLuaSocketUrl(lua_State* L); 41 | }; 42 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/auxiliar.h: -------------------------------------------------------------------------------- 1 | #ifndef AUXILIAR_H 2 | #define AUXILIAR_H 3 | /*=========================================================================*\ 4 | * Auxiliar routines for class hierarchy manipulation 5 | * LuaSocket toolkit (but completely independent of other LuaSocket modules) 6 | * 7 | * A LuaSocket class is a name associated with Lua metatables. A LuaSocket 8 | * group is a name associated with a class. A class can belong to any number 9 | * of groups. This module provides the functionality to: 10 | * 11 | * - create new classes 12 | * - add classes to groups 13 | * - set the class of objects 14 | * - check if an object belongs to a given class or group 15 | * - get the userdata associated to objects 16 | * - print objects in a pretty way 17 | * 18 | * LuaSocket class names follow the convention {}. Modules 19 | * can define any number of classes and groups. The module tcp.c, for 20 | * example, defines the classes tcp{master}, tcp{client} and tcp{server} and 21 | * the groups tcp{client,server} and tcp{any}. Module functions can then 22 | * perform type-checking on their arguments by either class or group. 23 | * 24 | * LuaSocket metatables define the __index metamethod as being a table. This 25 | * table has one field for each method supported by the class, and a field 26 | * "class" with the class name. 27 | * 28 | * The mapping from class name to the corresponding metatable and the 29 | * reverse mapping are done using lauxlib. 30 | \*=========================================================================*/ 31 | 32 | #include "lua.h" 33 | #include "lauxlib.h" 34 | 35 | int auxiliar_open(lua_State *L); 36 | void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); 37 | void auxiliar_add2group(lua_State *L, const char *classname, const char *group); 38 | void auxiliar_setclass(lua_State *L, const char *classname, int objidx); 39 | void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); 40 | void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); 41 | void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); 42 | void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); 43 | int auxiliar_checkboolean(lua_State *L, int objidx); 44 | int auxiliar_tostring(lua_State *L); 45 | int auxiliar_typeerror(lua_State *L, int narg, const char *tname); 46 | 47 | #endif /* AUXILIAR_H */ 48 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef BUF_H 2 | #define BUF_H 3 | /*=========================================================================*\ 4 | * Input/Output interface for Lua programs 5 | * LuaSocket toolkit 6 | * 7 | * Line patterns require buffering. Reading one character at a time involves 8 | * too many system calls and is very slow. This module implements the 9 | * LuaSocket interface for input/output on connected objects, as seen by 10 | * Lua programs. 11 | * 12 | * Input is buffered. Output is *not* buffered because there was no simple 13 | * way of making sure the buffered output data would ever be sent. 14 | * 15 | * The module is built on top of the I/O abstraction defined in io.h and the 16 | * timeout management is done with the timeout.h interface. 17 | \*=========================================================================*/ 18 | #include "lua.h" 19 | 20 | #include "io.h" 21 | #include "timeout.h" 22 | 23 | /* buffer size in bytes */ 24 | #define BUF_SIZE 8192 25 | 26 | /* buffer control structure */ 27 | typedef struct t_buffer_ { 28 | double birthday; /* throttle support info: creation time, */ 29 | size_t sent, received; /* bytes sent, and bytes received */ 30 | p_io io; /* IO driver used for this buffer */ 31 | p_timeout tm; /* timeout management for this buffer */ 32 | size_t first, last; /* index of first and last bytes of stored data */ 33 | char data[BUF_SIZE]; /* storage space for buffer data */ 34 | } t_buffer; 35 | typedef t_buffer *p_buffer; 36 | 37 | int buffer_open(lua_State *L); 38 | void buffer_init(p_buffer buf, p_io io, p_timeout tm); 39 | int buffer_meth_send(lua_State *L, p_buffer buf); 40 | int buffer_meth_receive(lua_State *L, p_buffer buf); 41 | int buffer_meth_getstats(lua_State *L, p_buffer buf); 42 | int buffer_meth_setstats(lua_State *L, p_buffer buf); 43 | int buffer_isempty(p_buffer buf); 44 | 45 | #endif /* BUF_H */ 46 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/except.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Simple exception support 3 | * LuaSocket toolkit 4 | \*=========================================================================*/ 5 | #include 6 | 7 | #include "lua.h" 8 | #include "lauxlib.h" 9 | 10 | #include "except.h" 11 | 12 | #if LUA_VERSION_NUM < 502 13 | #define lua_pcallk(L, na, nr, err, ctx, cont) \ 14 | (((void)ctx),((void)cont),lua_pcall(L, na, nr, err)) 15 | #endif 16 | 17 | #if LUA_VERSION_NUM < 503 18 | typedef int lua_KContext; 19 | #endif 20 | 21 | /*=========================================================================*\ 22 | * Internal function prototypes. 23 | \*=========================================================================*/ 24 | static int global_protect(lua_State *L); 25 | static int global_newtry(lua_State *L); 26 | static int protected_(lua_State *L); 27 | static int finalize(lua_State *L); 28 | static int do_nothing(lua_State *L); 29 | 30 | /* except functions */ 31 | static luaL_Reg func[] = { 32 | {"newtry", global_newtry}, 33 | {"protect", global_protect}, 34 | {NULL, NULL} 35 | }; 36 | 37 | /*-------------------------------------------------------------------------*\ 38 | * Try factory 39 | \*-------------------------------------------------------------------------*/ 40 | static void wrap(lua_State *L) { 41 | lua_createtable(L, 1, 0); 42 | lua_pushvalue(L, -2); 43 | lua_rawseti(L, -2, 1); 44 | lua_pushvalue(L, lua_upvalueindex(1)); 45 | lua_setmetatable(L, -2); 46 | } 47 | 48 | static int finalize(lua_State *L) { 49 | if (!lua_toboolean(L, 1)) { 50 | lua_pushvalue(L, lua_upvalueindex(2)); 51 | lua_call(L, 0, 0); 52 | lua_settop(L, 2); 53 | wrap(L); 54 | lua_error(L); 55 | return 0; 56 | } else return lua_gettop(L); 57 | } 58 | 59 | static int do_nothing(lua_State *L) { 60 | (void) L; 61 | return 0; 62 | } 63 | 64 | static int global_newtry(lua_State *L) { 65 | lua_settop(L, 1); 66 | if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); 67 | lua_pushvalue(L, lua_upvalueindex(1)); 68 | lua_insert(L, -2); 69 | lua_pushcclosure(L, finalize, 2); 70 | return 1; 71 | } 72 | 73 | /*-------------------------------------------------------------------------*\ 74 | * Protect factory 75 | \*-------------------------------------------------------------------------*/ 76 | static int unwrap(lua_State *L) { 77 | if (lua_istable(L, -1) && lua_getmetatable(L, -1)) { 78 | int r = lua_rawequal(L, -1, lua_upvalueindex(1)); 79 | lua_pop(L, 1); 80 | if (r) { 81 | lua_pushnil(L); 82 | lua_rawgeti(L, -2, 1); 83 | return 1; 84 | } 85 | } 86 | return 0; 87 | } 88 | 89 | static int protected_finish(lua_State *L, int status, lua_KContext ctx) { 90 | (void)ctx; 91 | if (status != 0 && status != LUA_YIELD) { 92 | if (unwrap(L)) return 2; 93 | else return lua_error(L); 94 | } else return lua_gettop(L); 95 | } 96 | 97 | #if LUA_VERSION_NUM == 502 98 | static int protected_cont(lua_State *L) { 99 | int ctx = 0; 100 | int status = lua_getctx(L, &ctx); 101 | return protected_finish(L, status, ctx); 102 | } 103 | #else 104 | #define protected_cont protected_finish 105 | #endif 106 | 107 | static int protected_(lua_State *L) { 108 | int status; 109 | lua_pushvalue(L, lua_upvalueindex(2)); 110 | lua_insert(L, 1); 111 | status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, protected_cont); 112 | return protected_finish(L, status, 0); 113 | } 114 | 115 | static int global_protect(lua_State *L) { 116 | lua_settop(L, 1); 117 | lua_pushvalue(L, lua_upvalueindex(1)); 118 | lua_insert(L, 1); 119 | lua_pushcclosure(L, protected_, 2); 120 | return 1; 121 | } 122 | 123 | /*-------------------------------------------------------------------------*\ 124 | * Init module 125 | \*-------------------------------------------------------------------------*/ 126 | int except_open(lua_State *L) { 127 | lua_newtable(L); /* metatable for wrapped exceptions */ 128 | lua_pushboolean(L, 0); 129 | lua_setfield(L, -2, "__metatable"); 130 | luaL_setfuncs(L, func, 1); 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/except.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPT_H 2 | #define EXCEPT_H 3 | /*=========================================================================*\ 4 | * Exception control 5 | * LuaSocket toolkit (but completely independent from other modules) 6 | * 7 | * This provides support for simple exceptions in Lua. During the 8 | * development of the HTTP/FTP/SMTP support, it became aparent that 9 | * error checking was taking a substantial amount of the coding. These 10 | * function greatly simplify the task of checking errors. 11 | * 12 | * The main idea is that functions should return nil as their first return 13 | * values when they find an error, and return an error message (or value) 14 | * following nil. In case of success, as long as the first value is not nil, 15 | * the other values don't matter. 16 | * 17 | * The idea is to nest function calls with the "try" function. This function 18 | * checks the first value, and, if it's falsy, wraps the second value in a 19 | * table with metatable and calls "error" on it. Otherwise, it returns all 20 | * values it received. Basically, it works like the Lua "assert" function, 21 | * but it creates errors targeted specifically at "protect". 22 | * 23 | * The "newtry" function is a factory for "try" functions that call a 24 | * finalizer in protected mode before calling "error". 25 | * 26 | * The "protect" function returns a new function that behaves exactly like 27 | * the function it receives, but the new function catches exceptions thrown 28 | * by "try" functions and returns nil followed by the error message instead. 29 | * 30 | * With these three functions, it's easy to write functions that throw 31 | * exceptions on error, but that don't interrupt the user script. 32 | \*=========================================================================*/ 33 | 34 | #include "lua.h" 35 | 36 | int except_open(lua_State *L); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/headers.lua.inc: -------------------------------------------------------------------------------- 1 | R"[========]( 2 | ----------------------------------------------------------------------------- 3 | -- Canonic header field capitalization 4 | -- LuaSocket toolkit. 5 | -- Author: Diego Nehab 6 | ----------------------------------------------------------------------------- 7 | local socket = require("socket") 8 | socket.headers = {} 9 | local _M = socket.headers 10 | 11 | _M.canonic = { 12 | ["accept"] = "Accept", 13 | ["accept-charset"] = "Accept-Charset", 14 | ["accept-encoding"] = "Accept-Encoding", 15 | ["accept-language"] = "Accept-Language", 16 | ["accept-ranges"] = "Accept-Ranges", 17 | ["action"] = "Action", 18 | ["alternate-recipient"] = "Alternate-Recipient", 19 | ["age"] = "Age", 20 | ["allow"] = "Allow", 21 | ["arrival-date"] = "Arrival-Date", 22 | ["authorization"] = "Authorization", 23 | ["bcc"] = "Bcc", 24 | ["cache-control"] = "Cache-Control", 25 | ["cc"] = "Cc", 26 | ["comments"] = "Comments", 27 | ["connection"] = "Connection", 28 | ["content-description"] = "Content-Description", 29 | ["content-disposition"] = "Content-Disposition", 30 | ["content-encoding"] = "Content-Encoding", 31 | ["content-id"] = "Content-ID", 32 | ["content-language"] = "Content-Language", 33 | ["content-length"] = "Content-Length", 34 | ["content-location"] = "Content-Location", 35 | ["content-md5"] = "Content-MD5", 36 | ["content-range"] = "Content-Range", 37 | ["content-transfer-encoding"] = "Content-Transfer-Encoding", 38 | ["content-type"] = "Content-Type", 39 | ["cookie"] = "Cookie", 40 | ["date"] = "Date", 41 | ["diagnostic-code"] = "Diagnostic-Code", 42 | ["dsn-gateway"] = "DSN-Gateway", 43 | ["etag"] = "ETag", 44 | ["expect"] = "Expect", 45 | ["expires"] = "Expires", 46 | ["final-log-id"] = "Final-Log-ID", 47 | ["final-recipient"] = "Final-Recipient", 48 | ["from"] = "From", 49 | ["host"] = "Host", 50 | ["if-match"] = "If-Match", 51 | ["if-modified-since"] = "If-Modified-Since", 52 | ["if-none-match"] = "If-None-Match", 53 | ["if-range"] = "If-Range", 54 | ["if-unmodified-since"] = "If-Unmodified-Since", 55 | ["in-reply-to"] = "In-Reply-To", 56 | ["keywords"] = "Keywords", 57 | ["last-attempt-date"] = "Last-Attempt-Date", 58 | ["last-modified"] = "Last-Modified", 59 | ["location"] = "Location", 60 | ["max-forwards"] = "Max-Forwards", 61 | ["message-id"] = "Message-ID", 62 | ["mime-version"] = "MIME-Version", 63 | ["original-envelope-id"] = "Original-Envelope-ID", 64 | ["original-recipient"] = "Original-Recipient", 65 | ["pragma"] = "Pragma", 66 | ["proxy-authenticate"] = "Proxy-Authenticate", 67 | ["proxy-authorization"] = "Proxy-Authorization", 68 | ["range"] = "Range", 69 | ["received"] = "Received", 70 | ["received-from-mta"] = "Received-From-MTA", 71 | ["references"] = "References", 72 | ["referer"] = "Referer", 73 | ["remote-mta"] = "Remote-MTA", 74 | ["reply-to"] = "Reply-To", 75 | ["reporting-mta"] = "Reporting-MTA", 76 | ["resent-bcc"] = "Resent-Bcc", 77 | ["resent-cc"] = "Resent-Cc", 78 | ["resent-date"] = "Resent-Date", 79 | ["resent-from"] = "Resent-From", 80 | ["resent-message-id"] = "Resent-Message-ID", 81 | ["resent-reply-to"] = "Resent-Reply-To", 82 | ["resent-sender"] = "Resent-Sender", 83 | ["resent-to"] = "Resent-To", 84 | ["retry-after"] = "Retry-After", 85 | ["return-path"] = "Return-Path", 86 | ["sender"] = "Sender", 87 | ["server"] = "Server", 88 | ["smtp-remote-recipient"] = "SMTP-Remote-Recipient", 89 | ["status"] = "Status", 90 | ["subject"] = "Subject", 91 | ["te"] = "TE", 92 | ["to"] = "To", 93 | ["trailer"] = "Trailer", 94 | ["transfer-encoding"] = "Transfer-Encoding", 95 | ["upgrade"] = "Upgrade", 96 | ["user-agent"] = "User-Agent", 97 | ["vary"] = "Vary", 98 | ["via"] = "Via", 99 | ["warning"] = "Warning", 100 | ["will-retry-until"] = "Will-Retry-Until", 101 | ["www-authenticate"] = "WWW-Authenticate", 102 | ["x-mailer"] = "X-Mailer", 103 | } 104 | 105 | return _M 106 | )[========]"; -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef INET_H 2 | #define INET_H 3 | /*=========================================================================*\ 4 | * Internet domain functions 5 | * LuaSocket toolkit 6 | * 7 | * This module implements the creation and connection of internet domain 8 | * sockets, on top of the socket.h interface, and the interface of with the 9 | * resolver. 10 | * 11 | * The function inet_aton is provided for the platforms where it is not 12 | * available. The module also implements the interface of the internet 13 | * getpeername and getsockname functions as seen by Lua programs. 14 | * 15 | * The Lua functions toip and tohostname are also implemented here. 16 | \*=========================================================================*/ 17 | #include "lua.h" 18 | #include "socket.h" 19 | #include "timeout.h" 20 | 21 | #ifdef _WIN32 22 | #define LUASOCKET_INET_ATON 23 | #endif 24 | 25 | int inet_open(lua_State *L); 26 | 27 | const char *inet_trycreate(p_socket ps, int family, int type, int protocol); 28 | const char *inet_tryconnect(p_socket ps, int *family, const char *address, 29 | const char *serv, p_timeout tm, struct addrinfo *connecthints); 30 | const char *inet_trybind(p_socket ps, int *family, const char *address, 31 | const char *serv, struct addrinfo *bindhints); 32 | const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); 33 | const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); 34 | 35 | int inet_meth_getpeername(lua_State *L, p_socket ps, int family); 36 | int inet_meth_getsockname(lua_State *L, p_socket ps, int family); 37 | 38 | int inet_optfamily(lua_State* L, int narg, const char* def); 39 | int inet_optsocktype(lua_State* L, int narg, const char* def); 40 | 41 | #ifdef LUASOCKET_INET_ATON 42 | int inet_aton(const char *cp, struct in_addr *inp); 43 | #endif 44 | 45 | #ifdef LUASOCKET_INET_PTON 46 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); 47 | int inet_pton(int af, const char *src, void *dst); 48 | #endif 49 | 50 | #endif /* INET_H */ 51 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/io.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * Input/Output abstraction 3 | * LuaSocket toolkit 4 | \*=========================================================================*/ 5 | #include "io.h" 6 | 7 | /*=========================================================================*\ 8 | * Exported functions 9 | \*=========================================================================*/ 10 | /*-------------------------------------------------------------------------*\ 11 | * Initializes C structure 12 | \*-------------------------------------------------------------------------*/ 13 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { 14 | io->send = send; 15 | io->recv = recv; 16 | io->error = error; 17 | io->ctx = ctx; 18 | } 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * I/O error strings 22 | \*-------------------------------------------------------------------------*/ 23 | const char *io_strerror(int err) { 24 | switch (err) { 25 | case IO_DONE: return NULL; 26 | case IO_CLOSED: return "closed"; 27 | case IO_TIMEOUT: return "timeout"; 28 | default: return "unknown error"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/io.h: -------------------------------------------------------------------------------- 1 | #ifndef IO_H 2 | #define IO_H 3 | /*=========================================================================*\ 4 | * Input/Output abstraction 5 | * LuaSocket toolkit 6 | * 7 | * This module defines the interface that LuaSocket expects from the 8 | * transport layer for streamed input/output. The idea is that if any 9 | * transport implements this interface, then the buffer.c functions 10 | * automatically work on it. 11 | * 12 | * The module socket.h implements this interface, and thus the module tcp.h 13 | * is very simple. 14 | \*=========================================================================*/ 15 | #include 16 | #include "lua.h" 17 | 18 | #include "timeout.h" 19 | 20 | /* IO error codes */ 21 | enum { 22 | IO_DONE = 0, /* operation completed successfully */ 23 | IO_TIMEOUT = -1, /* operation timed out */ 24 | IO_CLOSED = -2, /* the connection has been closed */ 25 | IO_UNKNOWN = -3 26 | }; 27 | 28 | /* interface to error message function */ 29 | typedef const char *(*p_error) ( 30 | void *ctx, /* context needed by send */ 31 | int err /* error code */ 32 | ); 33 | 34 | /* interface to send function */ 35 | typedef int (*p_send) ( 36 | void *ctx, /* context needed by send */ 37 | const char *data, /* pointer to buffer with data to send */ 38 | size_t count, /* number of bytes to send from buffer */ 39 | size_t *sent, /* number of bytes sent uppon return */ 40 | p_timeout tm /* timeout control */ 41 | ); 42 | 43 | /* interface to recv function */ 44 | typedef int (*p_recv) ( 45 | void *ctx, /* context needed by recv */ 46 | char *data, /* pointer to buffer where data will be writen */ 47 | size_t count, /* number of bytes to receive into buffer */ 48 | size_t *got, /* number of bytes received uppon return */ 49 | p_timeout tm /* timeout control */ 50 | ); 51 | 52 | /* IO driver definition */ 53 | typedef struct t_io_ { 54 | void *ctx; /* context needed by send/recv */ 55 | p_send send; /* send function pointer */ 56 | p_recv recv; /* receive function pointer */ 57 | p_error error; /* strerror function */ 58 | } t_io; 59 | typedef t_io *p_io; 60 | 61 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); 62 | const char *io_strerror(int err); 63 | 64 | #endif /* IO_H */ 65 | 66 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/luasocket.c: -------------------------------------------------------------------------------- 1 | /*=========================================================================*\ 2 | * LuaSocket toolkit 3 | * Networking support for the Lua language 4 | * Diego Nehab 5 | * 26/11/1999 6 | * 7 | * This library is part of an effort to progressively increase the network 8 | * connectivity of the Lua language. The Lua interface to networking 9 | * functions follows the Sockets API closely, trying to simplify all tasks 10 | * involved in setting up both client and server connections. The provided 11 | * IO routines, however, follow the Lua style, being very similar to the 12 | * standard Lua read and write functions. 13 | \*=========================================================================*/ 14 | 15 | /*=========================================================================*\ 16 | * Standard include files 17 | \*=========================================================================*/ 18 | #include "lua.h" 19 | #include "lauxlib.h" 20 | 21 | /*=========================================================================*\ 22 | * LuaSocket includes 23 | \*=========================================================================*/ 24 | #include "luasocket.h" 25 | #include "auxiliar.h" 26 | #include "except.h" 27 | #include "timeout.h" 28 | #include "buffer.h" 29 | #include "inet.h" 30 | #include "tcp.h" 31 | #include "udp.h" 32 | #include "select.h" 33 | 34 | /*-------------------------------------------------------------------------*\ 35 | * Internal function prototypes 36 | \*-------------------------------------------------------------------------*/ 37 | static int global_skip(lua_State *L); 38 | static int global_unload(lua_State *L); 39 | static int base_open(lua_State *L); 40 | 41 | /*-------------------------------------------------------------------------*\ 42 | * Modules and functions 43 | \*-------------------------------------------------------------------------*/ 44 | static const luaL_Reg mod[] = { 45 | {"auxiliar", auxiliar_open}, 46 | {"except", except_open}, 47 | {"timeout", timeout_open}, 48 | {"buffer", buffer_open}, 49 | {"inet", inet_open}, 50 | {"tcp", tcp_open}, 51 | {"udp", udp_open}, 52 | {"select", select_open}, 53 | {NULL, NULL} 54 | }; 55 | 56 | static luaL_Reg func[] = { 57 | {"skip", global_skip}, 58 | {"__unload", global_unload}, 59 | {NULL, NULL} 60 | }; 61 | 62 | /*-------------------------------------------------------------------------*\ 63 | * Skip a few arguments 64 | \*-------------------------------------------------------------------------*/ 65 | static int global_skip(lua_State *L) { 66 | int amount = (int) luaL_checkinteger(L, 1); 67 | int ret = lua_gettop(L) - amount - 1; 68 | return ret >= 0 ? ret : 0; 69 | } 70 | 71 | /*-------------------------------------------------------------------------*\ 72 | * Unloads the library 73 | \*-------------------------------------------------------------------------*/ 74 | static int global_unload(lua_State *L) { 75 | (void) L; 76 | socket_close(); 77 | return 0; 78 | } 79 | 80 | /*-------------------------------------------------------------------------*\ 81 | * Setup basic stuff. 82 | \*-------------------------------------------------------------------------*/ 83 | static int base_open(lua_State *L) { 84 | if (socket_open()) { 85 | /* export functions (and leave namespace table on top of stack) */ 86 | lua_newtable(L); 87 | luaL_setfuncs(L, func, 0); 88 | #ifdef LUASOCKET_DEBUG 89 | lua_pushstring(L, "_DEBUG"); 90 | lua_pushboolean(L, 1); 91 | lua_rawset(L, -3); 92 | #endif 93 | /* make version string available to scripts */ 94 | lua_pushstring(L, "_VERSION"); 95 | lua_pushstring(L, LUASOCKET_VERSION); 96 | lua_rawset(L, -3); 97 | return 1; 98 | } else { 99 | lua_pushstring(L, "unable to initialize library"); 100 | lua_error(L); 101 | return 0; 102 | } 103 | } 104 | 105 | /*-------------------------------------------------------------------------*\ 106 | * Initializes all library modules. 107 | \*-------------------------------------------------------------------------*/ 108 | LUASOCKET_API int luaopen_socket_core(lua_State *L) { 109 | int i; 110 | base_open(L); 111 | for (i = 0; mod[i].name; i++) mod[i].func(L); 112 | return 1; 113 | } 114 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/luasocket.h: -------------------------------------------------------------------------------- 1 | #ifndef LUASOCKET_H 2 | #define LUASOCKET_H 3 | /*=========================================================================*\ 4 | * LuaSocket toolkit 5 | * Networking support for the Lua language 6 | * Diego Nehab 7 | * 9/11/1999 8 | \*=========================================================================*/ 9 | #include "lua.h" 10 | 11 | /*-------------------------------------------------------------------------*\ 12 | * Current socket library version 13 | \*-------------------------------------------------------------------------*/ 14 | #define LUASOCKET_VERSION "LuaSocket 3.0-rc1" 15 | #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab" 16 | 17 | /*-------------------------------------------------------------------------*\ 18 | * This macro prefixes all exported API functions 19 | \*-------------------------------------------------------------------------*/ 20 | #ifndef LUASOCKET_API 21 | #define LUASOCKET_API extern 22 | #endif 23 | 24 | /*-------------------------------------------------------------------------*\ 25 | * Initializes the library. 26 | \*-------------------------------------------------------------------------*/ 27 | LUASOCKET_API int luaopen_socket_core(lua_State *L); 28 | 29 | #endif /* LUASOCKET_H */ 30 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/mbox.lua.inc: -------------------------------------------------------------------------------- 1 | R"[========]( 2 | local _M = {} 3 | 4 | if module then 5 | mbox = _M 6 | end 7 | 8 | function _M.split_message(message_s) 9 | local message = {} 10 | message_s = string.gsub(message_s, "\r\n", "\n") 11 | string.gsub(message_s, "^(.-\n)\n", function (h) message.headers = h end) 12 | string.gsub(message_s, "^.-\n\n(.*)", function (b) message.body = b end) 13 | if not message.body then 14 | string.gsub(message_s, "^\n(.*)", function (b) message.body = b end) 15 | end 16 | if not message.headers and not message.body then 17 | message.headers = message_s 18 | end 19 | return message.headers or "", message.body or "" 20 | end 21 | 22 | function _M.split_headers(headers_s) 23 | local headers = {} 24 | headers_s = string.gsub(headers_s, "\r\n", "\n") 25 | headers_s = string.gsub(headers_s, "\n[ ]+", " ") 26 | string.gsub("\n" .. headers_s, "\n([^\n]+)", function (h) table.insert(headers, h) end) 27 | return headers 28 | end 29 | 30 | function _M.parse_header(header_s) 31 | header_s = string.gsub(header_s, "\n[ ]+", " ") 32 | header_s = string.gsub(header_s, "\n+", "") 33 | local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") 34 | return name, value 35 | end 36 | 37 | function _M.parse_headers(headers_s) 38 | local headers_t = _M.split_headers(headers_s) 39 | local headers = {} 40 | for i = 1, #headers_t do 41 | local name, value = _M.parse_header(headers_t[i]) 42 | if name then 43 | name = string.lower(name) 44 | if headers[name] then 45 | headers[name] = headers[name] .. ", " .. value 46 | else headers[name] = value end 47 | end 48 | end 49 | return headers 50 | end 51 | 52 | function _M.parse_from(from) 53 | local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") 54 | if not address then 55 | _, __, address = string.find(from, "%s*(.+)%s*") 56 | end 57 | name = name or "" 58 | address = address or "" 59 | if name == "" then name = address end 60 | name = string.gsub(name, '"', "") 61 | return name, address 62 | end 63 | 64 | function _M.split_mbox(mbox_s) 65 | local mbox = {} 66 | mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" 67 | local nj, i, j = 1, 1, 1 68 | while 1 do 69 | i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) 70 | if not i then break end 71 | local message = string.sub(mbox_s, j, i-1) 72 | table.insert(mbox, message) 73 | j = nj+1 74 | end 75 | return mbox 76 | end 77 | 78 | function _M.parse(mbox_s) 79 | local mbox = _M.split_mbox(mbox_s) 80 | for i = 1, #mbox do 81 | mbox[i] = _M.parse_message(mbox[i]) 82 | end 83 | return mbox 84 | end 85 | 86 | function _M.parse_message(message_s) 87 | local message = {} 88 | message.headers, message.body = _M.split_message(message_s) 89 | message.headers = _M.parse_headers(message.headers) 90 | return message 91 | end 92 | 93 | return _M 94 | )[========]"; -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef MIME_H 2 | #define MIME_H 3 | /*=========================================================================*\ 4 | * Core MIME support 5 | * LuaSocket toolkit 6 | * 7 | * This module provides functions to implement transfer content encodings 8 | * and formatting conforming to RFC 2045. It is used by mime.lua, which 9 | * provide a higher level interface to this functionality. 10 | \*=========================================================================*/ 11 | #include "lua.h" 12 | 13 | /*-------------------------------------------------------------------------*\ 14 | * Current MIME library version 15 | \*-------------------------------------------------------------------------*/ 16 | #define MIME_VERSION "MIME 1.0.3" 17 | #define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab" 18 | #define MIME_AUTHORS "Diego Nehab" 19 | 20 | /*-------------------------------------------------------------------------*\ 21 | * This macro prefixes all exported API functions 22 | \*-------------------------------------------------------------------------*/ 23 | #ifndef MIME_API 24 | #define MIME_API extern 25 | #endif 26 | 27 | MIME_API int luaopen_mime_core(lua_State *L); 28 | 29 | #endif /* MIME_H */ 30 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/mime.lua.inc: -------------------------------------------------------------------------------- 1 | R"[========]( 2 | ----------------------------------------------------------------------------- 3 | -- MIME support for the Lua language. 4 | -- Author: Diego Nehab 5 | -- Conforming to RFCs 2045-2049 6 | ----------------------------------------------------------------------------- 7 | 8 | ----------------------------------------------------------------------------- 9 | -- Declare module and import dependencies 10 | ----------------------------------------------------------------------------- 11 | local base = _G 12 | local ltn12 = require("ltn12") 13 | local mime = require("mime.core") 14 | local io = require("io") 15 | local string = require("string") 16 | local _M = mime 17 | 18 | -- encode, decode and wrap algorithm tables 19 | local encodet, decodet, wrapt = {},{},{} 20 | 21 | _M.encodet = encodet 22 | _M.decodet = decodet 23 | _M.wrapt = wrapt 24 | 25 | -- creates a function that chooses a filter by name from a given table 26 | local function choose(table) 27 | return function(name, opt1, opt2) 28 | if base.type(name) ~= "string" then 29 | name, opt1, opt2 = "default", name, opt1 30 | end 31 | local f = table[name or "nil"] 32 | if not f then 33 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) 34 | else return f(opt1, opt2) end 35 | end 36 | end 37 | 38 | -- define the encoding filters 39 | encodet['base64'] = function() 40 | return ltn12.filter.cycle(_M.b64, "") 41 | end 42 | 43 | encodet['quoted-printable'] = function(mode) 44 | return ltn12.filter.cycle(_M.qp, "", 45 | (mode == "binary") and "=0D=0A" or "\r\n") 46 | end 47 | 48 | -- define the decoding filters 49 | decodet['base64'] = function() 50 | return ltn12.filter.cycle(_M.unb64, "") 51 | end 52 | 53 | decodet['quoted-printable'] = function() 54 | return ltn12.filter.cycle(_M.unqp, "") 55 | end 56 | 57 | local function format(chunk) 58 | if chunk then 59 | if chunk == "" then return "''" 60 | else return string.len(chunk) end 61 | else return "nil" end 62 | end 63 | 64 | -- define the line-wrap filters 65 | wrapt['text'] = function(length) 66 | length = length or 76 67 | return ltn12.filter.cycle(_M.wrp, length, length) 68 | end 69 | wrapt['base64'] = wrapt['text'] 70 | wrapt['default'] = wrapt['text'] 71 | 72 | wrapt['quoted-printable'] = function() 73 | return ltn12.filter.cycle(_M.qpwrp, 76, 76) 74 | end 75 | 76 | -- function that choose the encoding, decoding or wrap algorithm 77 | _M.encode = choose(encodet) 78 | _M.decode = choose(decodet) 79 | _M.wrap = choose(wrapt) 80 | 81 | -- define the end-of-line normalization filter 82 | function _M.normalize(marker) 83 | return ltn12.filter.cycle(_M.eol, 0, marker) 84 | end 85 | 86 | -- high level stuffing filter 87 | function _M.stuff() 88 | return ltn12.filter.cycle(_M.dot, 2) 89 | end 90 | 91 | return _M 92 | )[========]"; -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/options.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIONS_H 2 | #define OPTIONS_H 3 | /*=========================================================================*\ 4 | * Common option interface 5 | * LuaSocket toolkit 6 | * 7 | * This module provides a common interface to socket options, used mainly by 8 | * modules UDP and TCP. 9 | \*=========================================================================*/ 10 | 11 | #include "lua.h" 12 | #include "socket.h" 13 | 14 | /* option registry */ 15 | typedef struct t_opt { 16 | const char *name; 17 | int (*func)(lua_State *L, p_socket ps); 18 | } t_opt; 19 | typedef t_opt *p_opt; 20 | 21 | /* supported options for setoption */ 22 | int opt_set_dontroute(lua_State *L, p_socket ps); 23 | int opt_set_broadcast(lua_State *L, p_socket ps); 24 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps); 25 | int opt_set_keepalive(lua_State *L, p_socket ps); 26 | int opt_set_linger(lua_State *L, p_socket ps); 27 | int opt_set_reuseaddr(lua_State *L, p_socket ps); 28 | int opt_set_reuseport(lua_State *L, p_socket ps); 29 | int opt_set_ip_multicast_if(lua_State *L, p_socket ps); 30 | int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps); 31 | int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); 32 | int opt_set_ip_add_membership(lua_State *L, p_socket ps); 33 | int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); 34 | int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); 35 | int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); 36 | int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); 37 | int opt_set_ip6_add_membership(lua_State *L, p_socket ps); 38 | int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); 39 | int opt_set_ip6_v6only(lua_State *L, p_socket ps); 40 | 41 | /* supported options for getoption */ 42 | int opt_get_dontroute(lua_State *L, p_socket ps); 43 | int opt_get_broadcast(lua_State *L, p_socket ps); 44 | int opt_get_reuseaddr(lua_State *L, p_socket ps); 45 | int opt_get_reuseport(lua_State *L, p_socket ps); 46 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); 47 | int opt_get_keepalive(lua_State *L, p_socket ps); 48 | int opt_get_linger(lua_State *L, p_socket ps); 49 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); 50 | int opt_get_ip_multicast_if(lua_State *L, p_socket ps); 51 | int opt_get_error(lua_State *L, p_socket ps); 52 | int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); 53 | int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); 54 | int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); 55 | int opt_get_ip6_v6only(lua_State *L, p_socket ps); 56 | int opt_get_reuseport(lua_State *L, p_socket ps); 57 | 58 | /* invokes the appropriate option handler */ 59 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); 60 | int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/pierror.h: -------------------------------------------------------------------------------- 1 | #ifndef PIERROR_H 2 | #define PIERROR_H 3 | /*=========================================================================*\ 4 | * Error messages 5 | * Defines platform independent error messages 6 | \*=========================================================================*/ 7 | 8 | #define PIE_HOST_NOT_FOUND "host not found" 9 | #define PIE_ADDRINUSE "address already in use" 10 | #define PIE_ISCONN "already connected" 11 | #define PIE_ACCESS "permission denied" 12 | #define PIE_CONNREFUSED "connection refused" 13 | #define PIE_CONNABORTED "closed" 14 | #define PIE_CONNRESET "closed" 15 | #define PIE_TIMEDOUT "timeout" 16 | #define PIE_AGAIN "temporary failure in name resolution" 17 | #define PIE_BADFLAGS "invalid value for ai_flags" 18 | #define PIE_BADHINTS "invalid value for hints" 19 | #define PIE_FAIL "non-recoverable failure in name resolution" 20 | #define PIE_FAMILY "ai_family not supported" 21 | #define PIE_MEMORY "memory allocation failure" 22 | #define PIE_NONAME "host or service not provided, or not known" 23 | #define PIE_OVERFLOW "argument buffer overflow" 24 | #define PIE_PROTOCOL "resolved protocol is unknown" 25 | #define PIE_SERVICE "service not supported for socket type" 26 | #define PIE_SOCKTYPE "ai_socktype not supported" 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/select.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECT_H 2 | #define SELECT_H 3 | /*=========================================================================*\ 4 | * Select implementation 5 | * LuaSocket toolkit 6 | * 7 | * Each object that can be passed to the select function has to export 8 | * method getfd() which returns the descriptor to be passed to the 9 | * underlying select function. Another method, dirty(), should return 10 | * true if there is data ready for reading (required for buffered input). 11 | \*=========================================================================*/ 12 | 13 | int select_open(lua_State *L); 14 | 15 | #endif /* SELECT_H */ 16 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCKET_H 2 | #define SOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module 5 | * LuaSocket toolkit 6 | * 7 | * BSD Sockets and WinSock are similar, but there are a few irritating 8 | * differences. Also, not all *nix platforms behave the same. This module 9 | * (and the associated usocket.h and wsocket.h) factor these differences and 10 | * creates a interface compatible with the io.h module. 11 | \*=========================================================================*/ 12 | #include "io.h" 13 | 14 | /*=========================================================================*\ 15 | * Platform specific compatibilization 16 | \*=========================================================================*/ 17 | #ifdef _WIN32 18 | #include "wsocket.h" 19 | #else 20 | #include "usocket.h" 21 | #endif 22 | 23 | /*=========================================================================*\ 24 | * The connect and accept functions accept a timeout and their 25 | * implementations are somewhat complicated. We chose to move 26 | * the timeout control into this module for these functions in 27 | * order to simplify the modules that use them. 28 | \*=========================================================================*/ 29 | #include "timeout.h" 30 | 31 | /* we are lazy... */ 32 | typedef struct sockaddr SA; 33 | 34 | /*=========================================================================*\ 35 | * Functions bellow implement a comfortable platform independent 36 | * interface to sockets 37 | \*=========================================================================*/ 38 | int socket_open(void); 39 | int socket_close(void); 40 | void socket_destroy(p_socket ps); 41 | void socket_shutdown(p_socket ps, int how); 42 | int socket_sendto(p_socket ps, const char *data, size_t count, 43 | size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); 44 | int socket_recvfrom(p_socket ps, char *data, size_t count, 45 | size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); 46 | 47 | void socket_setnonblocking(p_socket ps); 48 | void socket_setblocking(p_socket ps); 49 | 50 | int socket_waitfd(p_socket ps, int sw, p_timeout tm); 51 | int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, 52 | p_timeout tm); 53 | 54 | int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); 55 | int socket_create(p_socket ps, int domain, int type, int protocol); 56 | int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); 57 | int socket_listen(p_socket ps, int backlog); 58 | int socket_accept(p_socket ps, p_socket pa, SA *addr, 59 | socklen_t *addr_len, p_timeout tm); 60 | 61 | const char *socket_hoststrerror(int err); 62 | const char *socket_gaistrerror(int err); 63 | const char *socket_strerror(int err); 64 | 65 | /* these are perfect to use with the io abstraction module 66 | and the buffered input module */ 67 | int socket_send(p_socket ps, const char *data, size_t count, 68 | size_t *sent, p_timeout tm); 69 | int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); 70 | int socket_write(p_socket ps, const char *data, size_t count, 71 | size_t *sent, p_timeout tm); 72 | int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); 73 | const char *socket_ioerror(p_socket ps, int err); 74 | 75 | int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); 76 | int socket_gethostbyname(const char *addr, struct hostent **hp); 77 | 78 | #endif /* SOCKET_H */ 79 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_H 2 | #define TCP_H 3 | /*=========================================================================*\ 4 | * TCP object 5 | * LuaSocket toolkit 6 | * 7 | * The tcp.h module is basicly a glue that puts together modules buffer.h, 8 | * timeout.h socket.h and inet.h to provide the LuaSocket TCP (AF_INET, 9 | * SOCK_STREAM) support. 10 | * 11 | * Three classes are defined: master, client and server. The master class is 12 | * a newly created tcp object, that has not been bound or connected. Server 13 | * objects are tcp objects bound to some local address. Client objects are 14 | * tcp objects either connected to some address or returned by the accept 15 | * method of a server object. 16 | \*=========================================================================*/ 17 | #include "lua.h" 18 | 19 | #include "buffer.h" 20 | #include "timeout.h" 21 | #include "socket.h" 22 | 23 | typedef struct t_tcp_ { 24 | t_socket sock; 25 | t_io io; 26 | t_buffer buf; 27 | t_timeout tm; 28 | int family; 29 | } t_tcp; 30 | 31 | typedef t_tcp *p_tcp; 32 | 33 | int tcp_open(lua_State *L); 34 | 35 | #endif /* TCP_H */ 36 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMEOUT_H 2 | #define TIMEOUT_H 3 | /*=========================================================================*\ 4 | * Timeout management functions 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | #include "lua.h" 8 | 9 | /* timeout control structure */ 10 | typedef struct t_timeout_ { 11 | double block; /* maximum time for blocking calls */ 12 | double total; /* total number of miliseconds for operation */ 13 | double start; /* time of start of operation */ 14 | } t_timeout; 15 | typedef t_timeout *p_timeout; 16 | 17 | int timeout_open(lua_State *L); 18 | void timeout_init(p_timeout tm, double block, double total); 19 | double timeout_get(p_timeout tm); 20 | double timeout_getretry(p_timeout tm); 21 | p_timeout timeout_markstart(p_timeout tm); 22 | double timeout_getstart(p_timeout tm); 23 | double timeout_gettime(void); 24 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); 25 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm); 26 | 27 | #define timeout_iszero(tm) ((tm)->block == 0.0) 28 | 29 | #endif /* TIMEOUT_H */ 30 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/udp.h: -------------------------------------------------------------------------------- 1 | #ifndef UDP_H 2 | #define UDP_H 3 | /*=========================================================================*\ 4 | * UDP object 5 | * LuaSocket toolkit 6 | * 7 | * The udp.h module provides LuaSocket with support for UDP protocol 8 | * (AF_INET, SOCK_DGRAM). 9 | * 10 | * Two classes are defined: connected and unconnected. UDP objects are 11 | * originally unconnected. They can be "connected" to a given address 12 | * with a call to the setpeername function. The same function can be used to 13 | * break the connection. 14 | \*=========================================================================*/ 15 | #include "lua.h" 16 | 17 | #include "timeout.h" 18 | #include "socket.h" 19 | 20 | #define UDP_DATAGRAMSIZE 8192 21 | 22 | typedef struct t_udp_ { 23 | t_socket sock; 24 | t_timeout tm; 25 | int family; 26 | } t_udp; 27 | typedef t_udp *p_udp; 28 | 29 | int udp_open(lua_State *L); 30 | 31 | #endif /* UDP_H */ 32 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/usocket.h: -------------------------------------------------------------------------------- 1 | #ifndef USOCKET_H 2 | #define USOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Unix 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | 8 | /*=========================================================================*\ 9 | * BSD include files 10 | \*=========================================================================*/ 11 | 12 | #ifndef _WIN32 13 | 14 | /* error codes */ 15 | #include 16 | /* close function */ 17 | #include 18 | /* fnctnl function and associated constants */ 19 | #include 20 | /* struct sockaddr */ 21 | #include 22 | /* socket function */ 23 | #include 24 | /* struct timeval */ 25 | #include 26 | /* gethostbyname and gethostbyaddr functions */ 27 | #include 28 | /* sigpipe handling */ 29 | #include 30 | /* IP stuff*/ 31 | #include 32 | #include 33 | /* TCP options (nagle algorithm disable) */ 34 | #include 35 | #include 36 | 37 | #ifndef SO_REUSEPORT 38 | #define SO_REUSEPORT SO_REUSEADDR 39 | #endif 40 | 41 | /* Some platforms use IPV6_JOIN_GROUP instead if 42 | * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */ 43 | #ifndef IPV6_ADD_MEMBERSHIP 44 | #ifdef IPV6_JOIN_GROUP 45 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP 46 | #endif /* IPV6_JOIN_GROUP */ 47 | #endif /* !IPV6_ADD_MEMBERSHIP */ 48 | 49 | /* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */ 50 | #ifndef IPV6_DROP_MEMBERSHIP 51 | #ifdef IPV6_LEAVE_GROUP 52 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP 53 | #endif /* IPV6_LEAVE_GROUP */ 54 | #endif /* !IPV6_DROP_MEMBERSHIP */ 55 | 56 | typedef int t_socket; 57 | typedef t_socket *p_socket; 58 | typedef struct sockaddr_storage t_sockaddr_storage; 59 | 60 | #define SOCKET_INVALID (-1) 61 | 62 | #endif // _WIN32 63 | 64 | #endif /* USOCKET_H */ 65 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibLuasocket/wsocket.h: -------------------------------------------------------------------------------- 1 | #ifndef WSOCKET_H 2 | #define WSOCKET_H 3 | /*=========================================================================*\ 4 | * Socket compatibilization module for Win32 5 | * LuaSocket toolkit 6 | \*=========================================================================*/ 7 | 8 | /*=========================================================================*\ 9 | * WinSock include files 10 | \*=========================================================================*/ 11 | 12 | #ifdef _WIN32 13 | 14 | #include 15 | #include 16 | 17 | typedef int socklen_t; 18 | typedef SOCKADDR_STORAGE t_sockaddr_storage; 19 | typedef SOCKET t_socket; 20 | typedef t_socket *p_socket; 21 | 22 | #ifndef IPV6_V6ONLY 23 | #define IPV6_V6ONLY 27 24 | #endif 25 | 26 | #define SOCKET_INVALID (INVALID_SOCKET) 27 | 28 | #ifndef SO_REUSEPORT 29 | #define SO_REUSEPORT SO_REUSEADDR 30 | #endif 31 | 32 | #ifndef AI_NUMERICSERV 33 | #define AI_NUMERICSERV (0) 34 | #endif 35 | 36 | #endif // _WIN32 37 | 38 | #endif /* WSOCKET_H */ 39 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibSproto/LibSproto.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class LibSproto : ModuleRules 6 | { 7 | public LibSproto(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core" }); 12 | 13 | PrivateDependencyModuleNames.AddRange(new string[] { "Lua" }); 14 | 15 | bEnableShadowVariableWarnings = false; 16 | bEnableUndefinedIdentifierWarnings = false; 17 | 18 | PublicDefinitions.Add("WITH_LibSproto=1"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibSproto/LibSproto.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | #include "LibSproto.h" 3 | 4 | #include "lua.hpp" 5 | 6 | 7 | extern "C" { 8 | #include "sproto.h" 9 | #include "msvcint.h" 10 | 11 | } 12 | #include "lsproto.c" 13 | IMPLEMENT_MODULE(FLibSprotoModule, LibSproto); 14 | 15 | void FLibSprotoModule::StartupModule() 16 | { 17 | 18 | } 19 | 20 | void FLibSprotoModule::ShutdownModule() 21 | { 22 | 23 | } 24 | 25 | void FLibSprotoModule::SetupLibSproto(lua_State* L) 26 | { 27 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 28 | 29 | luaL_requiref(L, "sproto.core", luaopen_sproto_core, 1); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibSproto/LibSproto.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | struct lua_State; 9 | 10 | class LIBSPROTO_API FLibSprotoModule : public IModuleInterface 11 | { 12 | public: 13 | 14 | /** IModuleInterface implementation */ 15 | virtual void StartupModule() override; 16 | virtual void ShutdownModule() override; 17 | 18 | void SetupLibSproto(lua_State* L); 19 | 20 | static inline FLibSprotoModule& Get() 21 | { 22 | return FModuleManager::LoadModuleChecked("LibSproto"); 23 | } 24 | 25 | static inline bool IsAvailable() 26 | { 27 | return FModuleManager::Get().IsModuleLoaded("LibSproto"); 28 | } 29 | 30 | protected: 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibSproto/msvcint.h: -------------------------------------------------------------------------------- 1 | #ifndef msvc_int_h 2 | #define msvc_int_h 3 | 4 | #ifdef _MSC_VER 5 | # define inline __inline 6 | # ifndef _MSC_STDINT_H_ 7 | # if (_MSC_VER < 1300) 8 | typedef signed char int8_t; 9 | typedef signed short int16_t; 10 | typedef signed int int32_t; 11 | typedef unsigned char uint8_t; 12 | typedef unsigned short uint16_t; 13 | typedef unsigned int uint32_t; 14 | # else 15 | typedef signed __int8 int8_t; 16 | typedef signed __int16 int16_t; 17 | typedef signed __int32 int32_t; 18 | typedef unsigned __int8 uint8_t; 19 | typedef unsigned __int16 uint16_t; 20 | typedef unsigned __int32 uint32_t; 21 | # endif 22 | typedef signed __int64 int64_t; 23 | typedef unsigned __int64 uint64_t; 24 | # endif 25 | 26 | #else 27 | 28 | #include 29 | 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/LibSproto/sproto.h: -------------------------------------------------------------------------------- 1 | #ifndef sproto_h 2 | #define sproto_h 3 | 4 | #include 5 | 6 | struct sproto; 7 | struct sproto_type; 8 | 9 | #define SPROTO_REQUEST 0 10 | #define SPROTO_RESPONSE 1 11 | 12 | // type (sproto_arg.type) 13 | #define SPROTO_TINTEGER 0 14 | #define SPROTO_TBOOLEAN 1 15 | #define SPROTO_TSTRING 2 16 | #define SPROTO_TSTRUCT 3 17 | 18 | // sub type of string (sproto_arg.extra) 19 | #define SPROTO_TSTRING_STRING 0 20 | #define SPROTO_TSTRING_BINARY 1 21 | 22 | #define SPROTO_CB_ERROR -1 23 | #define SPROTO_CB_NIL -2 24 | #define SPROTO_CB_NOARRAY -3 25 | 26 | struct sproto * sproto_create(const void * proto, size_t sz); 27 | void sproto_release(struct sproto *); 28 | 29 | int sproto_prototag(const struct sproto *, const char * name); 30 | const char * sproto_protoname(const struct sproto *, int proto); 31 | // SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response 32 | struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what); 33 | int sproto_protoresponse(const struct sproto *, int proto); 34 | 35 | struct sproto_type * sproto_type(const struct sproto *, const char * type_name); 36 | 37 | int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz); 38 | int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz); 39 | 40 | struct sproto_arg { 41 | void *ud; 42 | const char *tagname; 43 | int tagid; 44 | int type; 45 | struct sproto_type *subtype; 46 | void *value; 47 | int length; 48 | int index; // array base 1 49 | int mainindex; // for map 50 | int extra; // SPROTO_TINTEGER: decimal ; SPROTO_TSTRING 0:utf8 string 1:binary 51 | }; 52 | 53 | typedef int (*sproto_callback)(const struct sproto_arg *args); 54 | 55 | int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud); 56 | int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud); 57 | 58 | // for debug use 59 | void sproto_dump(struct sproto *); 60 | const char * sproto_name(struct sproto_type *); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/Lua.Build.cs: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | using System; 16 | using System.IO; 17 | using UnrealBuildTool; 18 | 19 | public class Lua : ModuleRules 20 | { 21 | public Lua(ReadOnlyTargetRules Target) : base(Target) 22 | { 23 | Type = ModuleType.External; 24 | 25 | if (Target.Platform == UnrealTargetPlatform.Win64 || Target.Platform == UnrealTargetPlatform.Mac || 26 | Target.Platform == UnrealTargetPlatform.IOS || Target.Platform == UnrealTargetPlatform.Android) 27 | { 28 | string LuaDynLibName = ""; 29 | string LuaDynamicLibPath = ""; 30 | 31 | if (Target.Platform == UnrealTargetPlatform.Win64) 32 | { 33 | LuaDynLibName = "Lua.dll"; 34 | LuaDynamicLibPath = Path.Combine(ModuleDirectory, "binaries/Win64", LuaDynLibName); 35 | 36 | string Format = Path.Combine(ModuleDirectory, "{0}/Win64/Lua.lib"); 37 | PublicAdditionalLibraries.Add(String.Format(Format, Target.bBuildEditor == true ? "binaries" : "lib")); 38 | } 39 | else if (Target.Platform == UnrealTargetPlatform.Mac) 40 | { 41 | LuaDynLibName = Path.Combine(ModuleDirectory, "binaries/Mac/liblua.dylib"); 42 | LuaDynamicLibPath = LuaDynLibName; 43 | 44 | if (!Target.bBuildEditor) 45 | { 46 | PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib/Mac/liblua.a")); 47 | } 48 | } 49 | else if (Target.Platform == UnrealTargetPlatform.IOS) 50 | { 51 | PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib/IOS/liblua.a")); 52 | } 53 | else // UnrealTargetPlatform.Android 54 | { 55 | //PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "lib/Android/ARMv7")); 56 | //PublicLibraryPaths.Add(Path.Combine(ModuleDirectory, "lib/Android/ARM64")); 57 | //PublicAdditionalLibraries.Add("lua"); 58 | PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib/Android/ARMv7/liblua.a")); 59 | PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib/Android/ARM64/liblua.a")); 60 | } 61 | 62 | if (Target.bBuildEditor == true) 63 | { 64 | PublicDelayLoadDLLs.Add(LuaDynLibName); 65 | RuntimeDependencies.Add(LuaDynamicLibPath); 66 | } 67 | 68 | PublicSystemIncludePaths.Add(Path.Combine(ModuleDirectory, "include")); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/binaries/Mac/liblua.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/binaries/Mac/liblua.dylib -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/binaries/Win64/Lua.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/binaries/Win64/Lua.dll -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/binaries/Win64/Lua.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/binaries/Win64/Lua.lib -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/include/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/lib/Android/ARM64/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/lib/Android/ARM64/liblua.a -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/lib/Android/ARMv7/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/lib/Android/ARMv7/liblua.a -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/lib/Mac/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/lib/Mac/liblua.a -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/lib/Win64/Lua.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/lib/Win64/Lua.lib -------------------------------------------------------------------------------- /UnLua/Source/ThirdParty/Lua/lib/iOS/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangweiiscoding/UnLuaWithLibs/e2226f660956d02605838c3d6be555614f25c3ab/UnLua/Source/ThirdParty/Lua/lib/iOS/liblua.a -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/BaseLib/LuaLib_Class.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaCore.h" 17 | #include "ReflectionUtils/ClassDesc.h" 18 | 19 | /** 20 | * Load a class. for example: UClass.Load("/Game/Core/Blueprints/AICharacter.AICharacter_C") 21 | */ 22 | int32 UClass_Load(lua_State *L) 23 | { 24 | int32 NumParams = lua_gettop(L); 25 | if (NumParams != 1) 26 | { 27 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 28 | return 0; 29 | } 30 | 31 | const char *ClassName = lua_tostring(L, 1); 32 | if (!ClassName) 33 | { 34 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid class name!"), ANSI_TO_TCHAR(__FUNCTION__)); 35 | return 0; 36 | } 37 | 38 | const TCHAR *Suffix = TEXT("_C"); 39 | FString ClassPath(ClassName); 40 | int32 Index = INDEX_NONE; 41 | ClassPath.FindChar(TCHAR('.'), Index); 42 | if (Index == INDEX_NONE) 43 | { 44 | ClassPath.FindLastChar(TCHAR('/'), Index); 45 | if (Index != INDEX_NONE) 46 | { 47 | const FString Name = ClassPath.Mid(Index + 1); 48 | ClassPath += TCHAR('.'); 49 | ClassPath += Name; 50 | ClassPath.AppendChars(Suffix, 2); 51 | } 52 | } 53 | else 54 | { 55 | if (ClassPath.Right(2) != TEXT("_C")) 56 | { 57 | ClassPath.AppendChars(TEXT("_C"), 2); 58 | } 59 | } 60 | 61 | FClassDesc *ClassDesc = RegisterClass(L, TCHAR_TO_ANSI(*ClassPath)); 62 | if (ClassDesc && ClassDesc->AsClass()) 63 | { 64 | UnLua::PushUObject(L, ClassDesc->AsClass()); 65 | } 66 | else 67 | { 68 | lua_pushnil(L); 69 | } 70 | 71 | return 1; 72 | } 73 | 74 | /** 75 | * Test whether this class is a child of another class 76 | */ 77 | static int32 UClass_IsChildOf(lua_State *L) 78 | { 79 | int32 NumParams = lua_gettop(L); 80 | if (NumParams != 2) 81 | { 82 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 83 | return 0; 84 | } 85 | 86 | UClass *SrcClass = Cast(UnLua::GetUObject(L, 1)); 87 | if (!SrcClass) 88 | { 89 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid source class!"), ANSI_TO_TCHAR(__FUNCTION__)); 90 | return 0; 91 | } 92 | 93 | UClass *TargetClass = Cast(UnLua::GetUObject(L, 2)); 94 | if (!TargetClass) 95 | { 96 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid target class!"), ANSI_TO_TCHAR(__FUNCTION__)); 97 | return 0; 98 | } 99 | 100 | bool bValid = SrcClass->IsChildOf(TargetClass); 101 | lua_pushboolean(L, bValid); 102 | return 1; 103 | } 104 | 105 | static const luaL_Reg UClassLib[] = 106 | { 107 | { "Load", UClass_Load }, 108 | { "IsChildOf", UClass_IsChildOf }, 109 | { nullptr, nullptr } 110 | }; 111 | 112 | BEGIN_EXPORT_REFLECTED_CLASS(UClass) 113 | ADD_LIB(UClassLib) 114 | END_EXPORT_CLASS() 115 | IMPLEMENT_EXPORTED_CLASS(UClass) 116 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/BaseLib/LuaLib_PrimitiveTypes.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | 17 | template 18 | struct TPrimitiveTypeWrapper 19 | { 20 | friend uint32 GetTypeHash(TPrimitiveTypeWrapper In) 21 | { 22 | #if ENGINE_MINOR_VERSION > 22 23 | static_assert(TModels::Value, "type must support GetTypeHash()!"); 24 | #else 25 | static_assert(THasGetTypeHash::Value, "type must support GetTypeHash()!"); 26 | #endif 27 | return GetTypeHash(In.Value); 28 | } 29 | 30 | explicit TPrimitiveTypeWrapper(T InValue) : Value(InValue) {} 31 | 32 | T Value; 33 | }; 34 | 35 | template 36 | struct TAggregateTypeWrapper 37 | { 38 | friend uint32 GetTypeHash(const TAggregateTypeWrapper &In) 39 | { 40 | #if ENGINE_MINOR_VERSION > 22 41 | static_assert(TModels::Value, "type must support GetTypeHash()!"); 42 | #else 43 | static_assert(THasGetTypeHash::Value, "type must support GetTypeHash()!"); 44 | #endif 45 | return GetTypeHash(In.Value); 46 | } 47 | 48 | explicit TAggregateTypeWrapper(const T &InValue) : Value(InValue) {} 49 | 50 | T Value; 51 | }; 52 | 53 | #define EXPORT_PRIMITIVE_TYPE(Type, WrapperType, ArgType) \ 54 | DEFINE_NAMED_TYPE(#Type, WrapperType) \ 55 | BEGIN_EXPORT_CLASS_EX(false, Type, , WrapperType, nullptr, ArgType) \ 56 | ADD_PROPERTY(Value) \ 57 | END_EXPORT_CLASS(Type) \ 58 | IMPLEMENT_EXPORTED_CLASS(Type) \ 59 | ADD_TYPE_INTERFACE(Type) 60 | 61 | /** 62 | * Macros to export primitive types 63 | */ 64 | EXPORT_PRIMITIVE_TYPE(int8, TPrimitiveTypeWrapper, int8) 65 | EXPORT_PRIMITIVE_TYPE(int16, TPrimitiveTypeWrapper, int16) 66 | EXPORT_PRIMITIVE_TYPE(int32, TPrimitiveTypeWrapper, int32) 67 | EXPORT_PRIMITIVE_TYPE(int64, TPrimitiveTypeWrapper, int64) 68 | EXPORT_PRIMITIVE_TYPE(uint8, TPrimitiveTypeWrapper, uint8) 69 | EXPORT_PRIMITIVE_TYPE(uint16, TPrimitiveTypeWrapper, uint16) 70 | EXPORT_PRIMITIVE_TYPE(uint32, TPrimitiveTypeWrapper, uint32) 71 | EXPORT_PRIMITIVE_TYPE(uint64, TPrimitiveTypeWrapper, uint64) 72 | EXPORT_PRIMITIVE_TYPE(float, TPrimitiveTypeWrapper, float) 73 | EXPORT_PRIMITIVE_TYPE(double, TPrimitiveTypeWrapper, double) 74 | EXPORT_PRIMITIVE_TYPE(bool, TPrimitiveTypeWrapper, bool) 75 | EXPORT_PRIMITIVE_TYPE(FName, TPrimitiveTypeWrapper, FName) 76 | EXPORT_PRIMITIVE_TYPE(FString, TAggregateTypeWrapper, const FString&) 77 | //EXPORT_PRIMITIVE_TYPE(FText, TAggregateTypeWrapper, const FText&) 78 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/BaseLib/LuaLib_World.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaCore.h" 17 | #include "LuaDynamicBinding.h" 18 | #include "Engine/World.h" 19 | 20 | /** 21 | * Spawn an actor. 22 | * for example: World:SpawnActor(WeaponClass, InitialTransform, ESpawnActorCollisionHandlingMethod.AlwaysSpawn, Player, Player, "Weapon.AK47_C", WeaponColor), 23 | * the last two parameters "Weapon.AK47_C" and 'WeaponColor' and optional. 24 | * see programming guide for detail. 25 | */ 26 | static int32 UWorld_SpawnActor(lua_State *L) 27 | { 28 | int32 NumParams = lua_gettop(L); 29 | if (NumParams < 2) 30 | { 31 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 32 | lua_pushnil(L); 33 | return 1; 34 | } 35 | 36 | UWorld *World = Cast(UnLua::GetUObject(L, 1)); 37 | if (!World) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid world!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | lua_pushnil(L); 41 | return 1; 42 | } 43 | 44 | UClass *Class = Cast(UnLua::GetUObject(L, 2)); 45 | if (!Class) 46 | { 47 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid class!"), ANSI_TO_TCHAR(__FUNCTION__)); 48 | lua_pushnil(L); 49 | return 1; 50 | } 51 | 52 | FTransform Transform; 53 | if (NumParams > 2) 54 | { 55 | FTransform *TransformPtr = (FTransform*)GetCppInstanceFast(L, 3); 56 | if (TransformPtr) 57 | { 58 | Transform = *TransformPtr; 59 | } 60 | } 61 | 62 | FActorSpawnParameters SpawnParameters; 63 | if (NumParams > 3) 64 | { 65 | uint8 CollisionHandlingOverride = (uint8)lua_tointeger(L, 4); 66 | SpawnParameters.SpawnCollisionHandlingOverride = (ESpawnActorCollisionHandlingMethod)CollisionHandlingOverride; 67 | } 68 | if (NumParams > 4) 69 | { 70 | AActor *Owner = Cast(UnLua::GetUObject(L, 5)); 71 | check(!Owner || (Owner && World == Owner->GetWorld())); 72 | SpawnParameters.Owner = Owner; 73 | } 74 | if (NumParams > 5) 75 | { 76 | AActor *Actor = Cast(UnLua::GetUObject(L, 6)); 77 | if (Actor) 78 | { 79 | APawn *Instigator = Cast(Actor); 80 | if (!Instigator) 81 | { 82 | Instigator = Actor->GetInstigator(); 83 | } 84 | SpawnParameters.Instigator = Instigator; 85 | } 86 | } 87 | 88 | { 89 | const char *ModuleName = NumParams > 6 ? lua_tostring(L, 7) : nullptr; 90 | int32 TableRef = INDEX_NONE; 91 | if (NumParams > 7 && lua_type(L, 8) == LUA_TTABLE) 92 | { 93 | lua_pushvalue(L, 8); 94 | TableRef = luaL_ref(L, LUA_REGISTRYINDEX); 95 | } 96 | FScopedLuaDynamicBinding Binding(L, Class, ANSI_TO_TCHAR(ModuleName), TableRef); 97 | AActor *NewActor = World->SpawnActor(Class, &Transform, SpawnParameters); 98 | UnLua::PushUObject(L, NewActor); 99 | } 100 | 101 | return 1; 102 | } 103 | 104 | static const luaL_Reg UWorldLib[] = 105 | { 106 | { "SpawnActor", UWorld_SpawnActor }, 107 | { nullptr, nullptr } 108 | }; 109 | 110 | BEGIN_EXPORT_REFLECTED_CLASS(UWorld) 111 | ADD_LIB(UWorldLib) 112 | END_EXPORT_CLASS() 113 | IMPLEMENT_EXPORTED_CLASS(UWorld) 114 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/CollisionHelper.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "CollisionHelper.h" 16 | #include "Engine/CollisionProfile.h" 17 | 18 | TArray FCollisionHelper::ChannelNames; 19 | UEnum* FCollisionHelper::CollisionChannelEnum; 20 | UEnum* FCollisionHelper::ObjectTypeQueryEnum; 21 | UEnum* FCollisionHelper::TraceTypeQueryEnum; 22 | 23 | void FCollisionHelper::Initialize() 24 | { 25 | CollisionChannelEnum = FindObject(ANY_PACKAGE, TEXT("ECollisionChannel")); 26 | ObjectTypeQueryEnum = FindObject(ANY_PACKAGE, TEXT("EObjectTypeQuery")); 27 | TraceTypeQueryEnum = FindObject(ANY_PACKAGE, TEXT("ETraceTypeQuery")); 28 | check(CollisionChannelEnum && ObjectTypeQueryEnum && TraceTypeQueryEnum); 29 | 30 | if (ChannelNames.Num() > 0) 31 | { 32 | return; 33 | } 34 | 35 | UCollisionProfile *CollisionProfile = UCollisionProfile::Get(); 36 | int32 ContainerIndex = 0; 37 | while (true) 38 | { 39 | FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ContainerIndex++); 40 | if (ChannelName == NAME_None) 41 | { 42 | break; 43 | } 44 | ChannelNames.Add(ChannelName); 45 | } 46 | } 47 | 48 | void FCollisionHelper::Cleanup() 49 | { 50 | ChannelNames.Empty(); 51 | } 52 | 53 | int32 FCollisionHelper::ConvertToCollisionChannel(FName Name) // ECollisionChannel 54 | { 55 | int32 Index = ChannelNames.Find(Name); 56 | if (Index == INDEX_NONE) 57 | { 58 | Index = CollisionChannelEnum->GetValueByName(Name); 59 | } 60 | return (ECollisionChannel)Index; 61 | } 62 | 63 | int32 FCollisionHelper::ConvertToObjectType(FName Name) // EObjectTypeQuery 64 | { 65 | int32 Index = ChannelNames.Find(Name); 66 | if (Index == INDEX_NONE) 67 | { 68 | Index = ObjectTypeQueryEnum->GetValueByName(Name); 69 | } 70 | return UEngineTypes::ConvertToObjectType((ECollisionChannel)Index); 71 | } 72 | 73 | int32 FCollisionHelper::ConvertToTraceType(FName Name) // ETraceTypeQuery 74 | { 75 | int32 Index = ChannelNames.Find(Name); 76 | if (Index == INDEX_NONE) 77 | { 78 | Index = TraceTypeQueryEnum->GetValueByName(Name); 79 | } 80 | return UEngineTypes::ConvertToTraceType((ECollisionChannel)Index); 81 | } 82 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/CollisionHelper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "EngineMinimal.h" 18 | 19 | class FCollisionHelper 20 | { 21 | public: 22 | static void Initialize(); 23 | static void Cleanup(); 24 | static int32 ConvertToCollisionChannel(FName Name); // ECollisionChannel 25 | static int32 ConvertToObjectType(FName Name); // EObjectTypeQuery 26 | static int32 ConvertToTraceType(FName Name); // ETraceTypeQuery 27 | 28 | private: 29 | static TArray ChannelNames; 30 | static UEnum *CollisionChannelEnum; 31 | static UEnum *ObjectTypeQueryEnum; 32 | static UEnum *TraceTypeQueryEnum; 33 | }; 34 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/DefaultParamCollection.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "DefaultParamCollection.h" 16 | #include "CoreUObject.h" 17 | 18 | TMap GDefaultParamCollection; 19 | 20 | #pragma optimize("", off) 21 | 22 | void CreateDefaultParamCollection() 23 | { 24 | static bool CollectionCreated = false; 25 | if (!CollectionCreated) 26 | { 27 | CollectionCreated = true; 28 | 29 | #include "DefaultParamCollection.inl" 30 | } 31 | } 32 | 33 | #pragma optimize("", on) 34 | 35 | void DestroyDefaultParamCollection() 36 | { 37 | for (TMap::TIterator FCIt(GDefaultParamCollection); FCIt; ++FCIt) 38 | { 39 | FFunctionCollection &FunctionCollection = FCIt.Value(); 40 | for (TMap::TIterator PCIt(FunctionCollection.Functions); PCIt; ++PCIt) 41 | { 42 | FParameterCollection &ParamCollection = PCIt.Value(); 43 | for (TMap::TIterator PVIt(ParamCollection.Parameters); PVIt; ++PVIt) 44 | { 45 | IParamValue *ParamValue = PVIt.Value(); 46 | delete ParamValue; 47 | } 48 | ParamCollection.Parameters.Empty(); 49 | } 50 | FunctionCollection.Functions.Empty(); 51 | } 52 | GDefaultParamCollection.Empty(); 53 | } 54 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/DefaultParamCollection.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreMinimal.h" 18 | 19 | class IParamValue 20 | { 21 | public: 22 | virtual ~IParamValue() {} 23 | 24 | virtual const void* GetValue() const = 0; 25 | }; 26 | 27 | template 28 | class TParamValue : public IParamValue 29 | { 30 | public: 31 | explicit TParamValue(const T &InValue) 32 | : Value(InValue) 33 | {} 34 | 35 | virtual const void* GetValue() const override { return &Value; } 36 | 37 | private: 38 | T Value; 39 | }; 40 | 41 | typedef TParamValue FBoolParamValue; 42 | typedef TParamValue FByteParamValue; 43 | typedef TParamValue FIntParamValue; 44 | typedef TParamValue FEnumParamValue; 45 | typedef TParamValue FFloatParamValue; 46 | typedef TParamValue FDoubleParamValue; 47 | typedef TParamValue FNameParamValue; 48 | typedef TParamValue FTextParamValue; 49 | typedef TParamValue FStringParamValue; 50 | typedef TParamValue FVectorParamValue; 51 | typedef TParamValue FVector2DParamValue; 52 | typedef TParamValue FRotatorParamValue; 53 | typedef TParamValue FLinearColorParamValue; 54 | typedef TParamValue FColorParamValue; 55 | 56 | struct FParameterCollection 57 | { 58 | TMap Parameters; 59 | }; 60 | 61 | struct FFunctionCollection 62 | { 63 | TMap Functions; 64 | }; 65 | 66 | extern TMap GDefaultParamCollection; 67 | 68 | extern void CreateDefaultParamCollection(); 69 | extern void DestroyDefaultParamCollection(); 70 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/LuaDynamicBinding.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "LuaDynamicBinding.h" 16 | #include "lua.hpp" 17 | 18 | FLuaDynamicBinding GLuaDynamicBinding; 19 | 20 | bool FLuaDynamicBinding::IsValid(UClass *InClass) const 21 | { 22 | //return Class && InClass->IsChildOf(Class) && ModuleName.Len() > 0; 23 | return Class && Class == InClass && ModuleName.Len() > 0; 24 | } 25 | 26 | bool FLuaDynamicBinding::Push(UClass *InClass, const TCHAR *InModuleName, int32 InInitializerTableRef) 27 | { 28 | FLuaDynamicBindingStackNode StackNode; 29 | 30 | StackNode.Class = Class; 31 | StackNode.ModuleName = ModuleName; 32 | StackNode.InitializerTableRef = InitializerTableRef; 33 | 34 | Stack.Push(StackNode); 35 | 36 | Class = InClass; 37 | ModuleName = InModuleName; 38 | InitializerTableRef = InInitializerTableRef; 39 | 40 | return true; 41 | } 42 | 43 | int32 FLuaDynamicBinding::Pop() 44 | { 45 | check(Stack.Num() > 0); 46 | 47 | FLuaDynamicBindingStackNode StackNode = Stack.Pop(); 48 | int32 TableRef = InitializerTableRef; 49 | 50 | Class = StackNode.Class; 51 | ModuleName = StackNode.ModuleName; 52 | InitializerTableRef = StackNode.InitializerTableRef; 53 | 54 | return TableRef; 55 | } 56 | 57 | FScopedLuaDynamicBinding::FScopedLuaDynamicBinding(lua_State *InL, UClass *Class, const TCHAR *ModuleName, int32 InitializerTableRef) 58 | : L(InL), bValid(false) 59 | { 60 | if (L) 61 | { 62 | bValid = GLuaDynamicBinding.Push(Class, ModuleName, InitializerTableRef); 63 | } 64 | } 65 | 66 | FScopedLuaDynamicBinding::~FScopedLuaDynamicBinding() 67 | { 68 | if (bValid) 69 | { 70 | int32 InitializerTableRef = GLuaDynamicBinding.Pop(); 71 | if (InitializerTableRef != INDEX_NONE) 72 | { 73 | check(L); 74 | luaL_unref(L, LUA_REGISTRYINDEX, InitializerTableRef); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/LuaDynamicBinding.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreUObject.h" 18 | 19 | struct FLuaDynamicBinding 20 | { 21 | FLuaDynamicBinding() 22 | : Class(nullptr), InitializerTableRef(INDEX_NONE) 23 | {} 24 | 25 | bool IsValid(UClass *InClass) const; 26 | 27 | UClass *Class; 28 | FString ModuleName; 29 | int32 InitializerTableRef; 30 | 31 | struct FLuaDynamicBindingStackNode 32 | { 33 | UClass *Class; 34 | FString ModuleName; 35 | int32 InitializerTableRef; 36 | }; 37 | 38 | TArray Stack; 39 | 40 | bool Push(UClass *InClass, const TCHAR *InModuleName, int32 InInitializerTableRef); 41 | int32 Pop(); 42 | }; 43 | 44 | extern FLuaDynamicBinding GLuaDynamicBinding; 45 | 46 | struct lua_State; 47 | 48 | class FScopedLuaDynamicBinding 49 | { 50 | public: 51 | FScopedLuaDynamicBinding(lua_State *InL, UClass *Class, const TCHAR *ModuleName, int32 InitializerTableRef); 52 | ~FScopedLuaDynamicBinding(); 53 | 54 | private: 55 | lua_State *L; 56 | bool bValid; 57 | }; 58 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/LuaFunctionInjection.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreUObject.h" 18 | #include "UnLuaCompatibility.h" 19 | 20 | enum 21 | { 22 | EX_CallLua = EX_Max - 1 23 | }; 24 | 25 | class FLuaInvoker 26 | { 27 | public: 28 | DECLARE_FUNCTION(execCallLua); 29 | }; 30 | 31 | bool IsOverridable(UFunction *Function); 32 | void GetOverridableFunctions(UClass *Class, TMap &Functions); 33 | UFunction* DuplicateUFunction(UFunction *TemplateFunction, UClass *OuterClass, FName NewFuncName); 34 | void RemoveUFunction(UFunction *Function, UClass *OuterClass); 35 | void OverrideUFunction(UFunction *Function, FNativeFuncPtr NativeFunc, void *Userdata, bool bInsertOpcodes = true); 36 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FColor.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FColor_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FColor); 22 | FColor *V = new(Userdata) FColor(ForceInitToZero); 23 | if (NumParams > 1) 24 | { 25 | V->R = (uint8)lua_tonumber(L, 2); 26 | } 27 | if (NumParams > 2) 28 | { 29 | V->G = (uint8)lua_tonumber(L, 3); 30 | } 31 | if (NumParams > 3) 32 | { 33 | V->B = (uint8)lua_tonumber(L, 4); 34 | } 35 | if (NumParams > 4) 36 | { 37 | V->A = (uint8)lua_tonumber(L, 5); 38 | } 39 | return 1; 40 | } 41 | 42 | static int32 FColor_Set(lua_State *L) 43 | { 44 | int32 NumParams = lua_gettop(L); 45 | if (NumParams < 1) 46 | { 47 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 48 | return 0; 49 | } 50 | 51 | FColor *A = (FColor*)GetCppInstanceFast(L, 1); 52 | if (!A) 53 | { 54 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FColor!"), ANSI_TO_TCHAR(__FUNCTION__)); 55 | return 0; 56 | } 57 | if (NumParams > 1) 58 | { 59 | A->R = (uint8)lua_tonumber(L, 2); 60 | } 61 | if (NumParams > 2) 62 | { 63 | A->G = (uint8)lua_tonumber(L, 3); 64 | } 65 | if (NumParams > 3) 66 | { 67 | A->B = (uint8)lua_tonumber(L, 4); 68 | } 69 | if (NumParams > 4) 70 | { 71 | A->A = (uint8)lua_tonumber(L, 5); 72 | } 73 | return 0; 74 | } 75 | 76 | static int32 FColor_Add(lua_State *L) 77 | { 78 | int32 NumParams = lua_gettop(L); 79 | if (NumParams < 2) 80 | { 81 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 82 | return 0; 83 | } 84 | 85 | FColor *A = (FColor*)GetCppInstanceFast(L, 1); 86 | if (!A) 87 | { 88 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FColor A!"), ANSI_TO_TCHAR(__FUNCTION__)); 89 | return 0; 90 | } 91 | FColor *B = (FColor*)GetCppInstanceFast(L, 2); 92 | if (!B) 93 | { 94 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FColor B!"), ANSI_TO_TCHAR(__FUNCTION__)); 95 | return 0; 96 | } 97 | 98 | FColor C = *A; 99 | C += (*B); 100 | 101 | void *Userdata = NewTypedUserdata(L, FColor); 102 | FColor *V = new(Userdata) FColor(C); 103 | return 1; 104 | } 105 | 106 | static const luaL_Reg FColorLib[] = 107 | { 108 | { "Set", FColor_Set }, 109 | { "__add", FColor_Add }, 110 | { "__call", FColor_New }, 111 | { "__tostring", UnLua::TMathUtils::ToString }, 112 | { nullptr, nullptr } 113 | }; 114 | 115 | BEGIN_EXPORT_REFLECTED_CLASS(FColor) 116 | ADD_FUNCTION_EX("Add", void, operator+=, const FColor&) 117 | ADD_NAMED_FUNCTION("ToLinearColor", ReinterpretAsLinear) 118 | ADD_LIB(FColorLib) 119 | END_EXPORT_CLASS() 120 | IMPLEMENT_EXPORTED_CLASS(FColor) 121 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FIntPoint.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FIntPoint_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FIntPoint); 22 | FIntPoint *V = new(Userdata) FIntPoint(0.0f, 0.0f); 23 | UnLua::TFieldSetter2::Set(L, NumParams, &V->X); 24 | return 1; 25 | } 26 | 27 | static int32 FIntPoint_Set(lua_State *L) 28 | { 29 | int32 NumParams = lua_gettop(L); 30 | if (NumParams < 1) 31 | { 32 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 33 | return 0; 34 | } 35 | 36 | FIntPoint *V = (FIntPoint*)GetCppInstanceFast(L, 1); 37 | if (!V) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FIntPoint!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | return 0; 41 | } 42 | 43 | UnLua::TFieldSetter2::Set(L, NumParams, &V->X); 44 | return 0; 45 | } 46 | 47 | static int32 FIntPoint_UNM(lua_State *L) 48 | { 49 | FIntPoint *V = (FIntPoint*)GetCppInstanceFast(L, 1); 50 | if (!V) 51 | { 52 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FIntPoint!"), ANSI_TO_TCHAR(__FUNCTION__)); 53 | return 0; 54 | } 55 | 56 | void *Userdata = NewTypedUserdata(L, FIntPoint); 57 | new(Userdata) FIntPoint(-V->X, -V->Y); 58 | return 1; 59 | } 60 | 61 | static const luaL_Reg FIntPointLib[] = 62 | { 63 | { "Set", FIntPoint_Set }, 64 | { "Add", UnLua::TMathCalculation, true>::Calculate }, 65 | { "Sub", UnLua::TMathCalculation, true>::Calculate }, 66 | { "Mul", UnLua::TMathCalculation, true>::Calculate }, 67 | { "Div", UnLua::TMathCalculation, true>::Calculate }, 68 | { "__add", UnLua::TMathCalculation>::Calculate }, 69 | { "__sub", UnLua::TMathCalculation>::Calculate }, 70 | { "__mul", UnLua::TMathCalculation>::Calculate }, 71 | { "__div", UnLua::TMathCalculation>::Calculate }, 72 | { "__tostring", UnLua::TMathUtils::ToString }, 73 | { "__unm", FIntPoint_UNM }, 74 | { "__call", FIntPoint_New }, 75 | { nullptr, nullptr } 76 | }; 77 | 78 | BEGIN_EXPORT_REFLECTED_CLASS(FIntPoint) 79 | ADD_FUNCTION(Size) 80 | ADD_FUNCTION(SizeSquared) 81 | ADD_LIB(FIntPointLib) 82 | END_EXPORT_CLASS() 83 | IMPLEMENT_EXPORTED_CLASS(FIntPoint) 84 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FIntVector.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FIntVector_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FIntVector); 22 | FIntVector *V = new(Userdata) FIntVector(0.0f, 0.0f, 0.0f); 23 | UnLua::TFieldSetter3::Set(L, NumParams, &V->X); 24 | return 1; 25 | } 26 | 27 | static int32 FIntVector_Set(lua_State *L) 28 | { 29 | int32 NumParams = lua_gettop(L); 30 | if (NumParams < 1) 31 | { 32 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 33 | return 0; 34 | } 35 | 36 | FIntVector *V = (FIntVector*)GetCppInstanceFast(L, 1); 37 | if (!V) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FIntVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | return 0; 41 | } 42 | 43 | UnLua::TFieldSetter3::Set(L, NumParams, &V->X); 44 | return 0; 45 | } 46 | 47 | static int32 FIntVector_SizeSquared(lua_State *L) 48 | { 49 | int32 NumParams = lua_gettop(L); 50 | if (NumParams < 1) 51 | { 52 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 53 | return 0; 54 | } 55 | 56 | FIntVector *V = (FIntVector*)GetCppInstanceFast(L, 1); 57 | if (!V) 58 | { 59 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FIntVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 60 | return 0; 61 | } 62 | 63 | int32 S = V->X * V->X + V->Y * V->Y + V->Z * V->Z; 64 | lua_pushnumber(L, S); 65 | return 1; 66 | } 67 | 68 | static int32 FIntVector_UNM(lua_State *L) 69 | { 70 | FIntVector *V = (FIntVector*)GetCppInstanceFast(L, 1); 71 | if (!V) 72 | { 73 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FIntVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 74 | return 0; 75 | } 76 | 77 | void *Userdata = NewTypedUserdata(L, FIntVector); 78 | new(Userdata) FIntVector(-V->X, -V->Y, -V->Z); 79 | return 1; 80 | } 81 | 82 | static const luaL_Reg FIntVectorLib[] = 83 | { 84 | { "Set", FIntVector_Set }, 85 | { "SizeSquared", FIntVector_SizeSquared }, 86 | { "Add", UnLua::TMathCalculation, true>::Calculate }, 87 | { "Sub", UnLua::TMathCalculation, true>::Calculate }, 88 | { "Mul", UnLua::TMathCalculation, true>::Calculate }, 89 | { "Div", UnLua::TMathCalculation, true>::Calculate }, 90 | { "__add", UnLua::TMathCalculation>::Calculate }, 91 | { "__sub", UnLua::TMathCalculation>::Calculate }, 92 | { "__mul", UnLua::TMathCalculation>::Calculate }, 93 | { "__div", UnLua::TMathCalculation>::Calculate }, 94 | { "__tostring", UnLua::TMathUtils::ToString }, 95 | { "__unm", FIntVector_UNM }, 96 | { "__call", FIntVector_New }, 97 | { nullptr, nullptr } 98 | }; 99 | 100 | BEGIN_EXPORT_REFLECTED_CLASS(FIntVector) 101 | ADD_FUNCTION(Size) 102 | ADD_LIB(FIntVectorLib) 103 | END_EXPORT_CLASS() 104 | IMPLEMENT_EXPORTED_CLASS(FIntVector) 105 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FLinearColor.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FLinearColor_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FLinearColor); 22 | FLinearColor *V = new(Userdata) FLinearColor(ForceInit); 23 | UnLua::TFieldSetter4::Set(L, NumParams, &V->R); 24 | return 1; 25 | } 26 | 27 | static int32 FLinearColor_Set(lua_State *L) 28 | { 29 | int32 NumParams = lua_gettop(L); 30 | if (NumParams < 1) 31 | { 32 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 33 | return 0; 34 | } 35 | 36 | FLinearColor *V = (FLinearColor*)GetCppInstanceFast(L, 1); 37 | if (!V) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FLinearColor!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | return 0; 41 | } 42 | 43 | UnLua::TFieldSetter4::Set(L, NumParams, &V->R); 44 | return 0; 45 | } 46 | 47 | static const luaL_Reg FLinearColorLib[] = 48 | { 49 | { "Set", FLinearColor_Set }, 50 | { "Add", UnLua::TMathCalculation, true>::Calculate }, 51 | { "Sub", UnLua::TMathCalculation, true>::Calculate }, 52 | { "Mul", UnLua::TMathCalculation, true>::Calculate }, 53 | { "Div", UnLua::TMathCalculation, true>::Calculate }, 54 | { "__add", UnLua::TMathCalculation>::Calculate }, 55 | { "__sub", UnLua::TMathCalculation>::Calculate }, 56 | { "__mul", UnLua::TMathCalculation>::Calculate }, 57 | { "__div", UnLua::TMathCalculation>::Calculate }, 58 | { "__tostring", UnLua::TMathUtils::ToString }, 59 | { "__call", FLinearColor_New }, 60 | { nullptr, nullptr } 61 | }; 62 | 63 | BEGIN_EXPORT_REFLECTED_CLASS(FLinearColor) 64 | ADD_FUNCTION(ToFColor) 65 | ADD_NAMED_FUNCTION("Clamp", GetClamped) 66 | ADD_LIB(FLinearColorLib) 67 | END_EXPORT_CLASS() 68 | IMPLEMENT_EXPORTED_CLASS(FLinearColor) 69 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FTransform.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FTransform_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FTransform); 22 | FTransform *V = new(Userdata) FTransform; 23 | if (NumParams > 1) 24 | { 25 | V->SetRotation(*((FQuat*)GetCppInstanceFast(L, 2))); 26 | } 27 | if (NumParams > 2) 28 | { 29 | V->SetTranslation(*((FVector*)GetCppInstanceFast(L, 3))); 30 | } 31 | if (NumParams > 3) 32 | { 33 | V->SetScale3D(*((FVector*)GetCppInstanceFast(L, 4))); 34 | } 35 | return 1; 36 | } 37 | 38 | static int32 FTransform_Blend(lua_State *L) 39 | { 40 | int32 NumParams = lua_gettop(L); 41 | if (NumParams < 3) 42 | { 43 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 44 | return 0; 45 | } 46 | 47 | FTransform *A = (FTransform*)GetCppInstanceFast(L, 1); 48 | if (!A) 49 | { 50 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FTransform A!"), ANSI_TO_TCHAR(__FUNCTION__)); 51 | return 0; 52 | } 53 | FTransform *B = (FTransform*)GetCppInstanceFast(L, 2); 54 | if (!B) 55 | { 56 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FTransform B!"), ANSI_TO_TCHAR(__FUNCTION__)); 57 | return 0; 58 | } 59 | 60 | if (NumParams > 3) 61 | { 62 | FTransform *C = (FTransform*)GetCppInstanceFast(L, 3); 63 | if (!C) 64 | { 65 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FTransform C!"), ANSI_TO_TCHAR(__FUNCTION__)); 66 | return 0; 67 | } 68 | float Alpha = lua_tonumber(L, 4); 69 | A->Blend(*B, *C, Alpha); 70 | } 71 | else 72 | { 73 | float Alpha = lua_tonumber(L, 3); 74 | A->BlendWith(*B, Alpha); 75 | } 76 | return 0; 77 | } 78 | 79 | static const luaL_Reg FTransformLib[] = 80 | { 81 | { "Blend", FTransform_Blend }, 82 | { "Mul", UnLua::TMathCalculation, true, UnLua::TMul>::Calculate }, 83 | { "__mul", UnLua::TMathCalculation, false, UnLua::TMul>::Calculate }, 84 | { "__tostring", UnLua::TMathUtils::ToString }, 85 | { "__call", FTransform_New }, 86 | { nullptr, nullptr } 87 | }; 88 | 89 | BEGIN_EXPORT_REFLECTED_CLASS(FTransform) 90 | ADD_FUNCTION(Inverse) 91 | ADD_FUNCTION(TransformPosition) 92 | ADD_FUNCTION(TransformPositionNoScale) 93 | ADD_FUNCTION(InverseTransformPosition) 94 | ADD_FUNCTION(InverseTransformPositionNoScale) 95 | ADD_FUNCTION(TransformVector) 96 | ADD_FUNCTION(TransformVectorNoScale) 97 | ADD_FUNCTION(InverseTransformVector) 98 | ADD_FUNCTION(InverseTransformVectorNoScale) 99 | ADD_FUNCTION(TransformRotation) 100 | ADD_FUNCTION(InverseTransformRotation) 101 | ADD_CONST_FUNCTION_EX("__add", FTransform, operator+, const FTransform&) 102 | ADD_FUNCTION_EX("Add", FTransform&, operator+=, const FTransform&) 103 | ADD_LIB(FTransformLib) 104 | END_EXPORT_CLASS() 105 | IMPLEMENT_EXPORTED_CLASS(FTransform) 106 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FVector.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FVector_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FVector); 22 | FVector *V = new(Userdata) FVector(0.0f); 23 | UnLua::TFieldSetter3::Set(L, NumParams, &V->X); 24 | return 1; 25 | } 26 | 27 | static int32 FVector_Set(lua_State *L) 28 | { 29 | int32 NumParams = lua_gettop(L); 30 | if (NumParams < 1) 31 | { 32 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 33 | return 0; 34 | } 35 | 36 | FVector *V = (FVector*)GetCppInstanceFast(L, 1); 37 | if (!V) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | return 0; 41 | } 42 | 43 | UnLua::TFieldSetter3::Set(L, NumParams, &V->X); 44 | return 0; 45 | } 46 | 47 | static int32 FVector_Normalize(lua_State *L) 48 | { 49 | int32 NumParams = lua_gettop(L); 50 | if (NumParams != 1) 51 | { 52 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 53 | return 0; 54 | } 55 | 56 | FVector *V = (FVector*)GetCppInstanceFast(L, 1); 57 | if (!V) 58 | { 59 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 60 | return 0; 61 | } 62 | 63 | lua_pushboolean(L, V->Normalize()); 64 | return 1; 65 | } 66 | 67 | static int32 FVector_UNM(lua_State *L) 68 | { 69 | FVector *V = (FVector*)GetCppInstanceFast(L, 1); 70 | if (!V) 71 | { 72 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FVector!"), ANSI_TO_TCHAR(__FUNCTION__)); 73 | return 0; 74 | } 75 | 76 | void *Userdata = NewTypedUserdata(L, FVector); 77 | new(Userdata) FVector(-(*V)); 78 | return 1; 79 | } 80 | 81 | static const luaL_Reg FVectorLib[] = 82 | { 83 | { "Set", FVector_Set }, 84 | { "Normalize", FVector_Normalize }, 85 | { "Add", UnLua::TMathCalculation, true>::Calculate }, 86 | { "Sub", UnLua::TMathCalculation, true>::Calculate }, 87 | { "Mul", UnLua::TMathCalculation, true>::Calculate }, 88 | { "Div", UnLua::TMathCalculation, true>::Calculate }, 89 | { "__add", UnLua::TMathCalculation>::Calculate }, 90 | { "__sub", UnLua::TMathCalculation>::Calculate }, 91 | { "__mul", UnLua::TMathCalculation>::Calculate }, 92 | { "__div", UnLua::TMathCalculation>::Calculate }, 93 | { "__tostring", UnLua::TMathUtils::ToString }, 94 | { "__unm", FVector_UNM }, 95 | { "__call", FVector_New }, 96 | { nullptr, nullptr } 97 | }; 98 | 99 | BEGIN_EXPORT_REFLECTED_CLASS(FVector) 100 | ADD_CONST_FUNCTION_EX("Dot", float, operator|, const FVector&) 101 | ADD_CONST_FUNCTION_EX("Cross", FVector, operator^, const FVector&) 102 | ADD_FUNCTION(Size) 103 | ADD_FUNCTION(Size2D) 104 | ADD_FUNCTION(SizeSquared) 105 | ADD_FUNCTION(SizeSquared2D) 106 | ADD_STATIC_FUNCTION(Dist) 107 | ADD_STATIC_FUNCTION(Dist2D) 108 | ADD_STATIC_FUNCTION(DistSquared) 109 | ADD_STATIC_FUNCTION(DistSquared2D) 110 | ADD_FUNCTION(IsNormalized) 111 | ADD_FUNCTION(CosineAngle2D) 112 | ADD_FUNCTION(RotateAngleAxis) 113 | ADD_NAMED_FUNCTION("ToRotator", ToOrientationRotator) 114 | ADD_NAMED_FUNCTION("ToQuat", ToOrientationQuat) 115 | ADD_LIB(FVectorLib) 116 | END_EXPORT_CLASS() 117 | IMPLEMENT_EXPORTED_CLASS(FVector) 118 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/MathLib/LuaLib_FVector4.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEx.h" 16 | #include "LuaLib_Math.h" 17 | 18 | static int32 FVector4_New(lua_State *L) 19 | { 20 | int32 NumParams = lua_gettop(L); 21 | void *Userdata = NewTypedUserdata(L, FVector4); 22 | FVector4 *V = new(Userdata) FVector4; 23 | UnLua::TFieldSetter4::Set(L, NumParams, &V->X); 24 | return 1; 25 | } 26 | 27 | static int32 FVector4_Set(lua_State *L) 28 | { 29 | int32 NumParams = lua_gettop(L); 30 | if (NumParams < 1) 31 | { 32 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid parameters!"), ANSI_TO_TCHAR(__FUNCTION__)); 33 | return 0; 34 | } 35 | 36 | FVector4 *V = (FVector4*)GetCppInstanceFast(L, 1); 37 | if (!V) 38 | { 39 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FVector4!"), ANSI_TO_TCHAR(__FUNCTION__)); 40 | return 0; 41 | } 42 | 43 | UnLua::TFieldSetter4::Set(L, NumParams, &V->X); 44 | return 0; 45 | } 46 | 47 | static int32 FVector4_UNM(lua_State *L) 48 | { 49 | FVector4 *V = (FVector4*)GetCppInstanceFast(L, 1); 50 | if (!V) 51 | { 52 | UE_LOG(LogUnLua, Log, TEXT("%s: Invalid FVector4!"), ANSI_TO_TCHAR(__FUNCTION__)); 53 | return 0; 54 | } 55 | 56 | void *Userdata = NewTypedUserdata(L, FVector4); 57 | new(Userdata) FVector4(-(*V)); 58 | return 1; 59 | } 60 | 61 | static const luaL_Reg FVector4Lib[] = 62 | { 63 | { "Set", FVector4_Set }, 64 | { "Add", UnLua::TMathCalculation, true>::Calculate }, 65 | { "Sub", UnLua::TMathCalculation, true>::Calculate }, 66 | { "Mul", UnLua::TMathCalculation, true>::Calculate }, 67 | { "Div", UnLua::TMathCalculation, true>::Calculate }, 68 | { "__add", UnLua::TMathCalculation>::Calculate }, 69 | { "__sub", UnLua::TMathCalculation>::Calculate }, 70 | { "__mul", UnLua::TMathCalculation>::Calculate }, 71 | { "__div", UnLua::TMathCalculation>::Calculate }, 72 | { "__tostring", UnLua::TMathUtils::ToString }, 73 | { "__unm", FVector4_UNM }, 74 | { "__call", FVector4_New }, 75 | { nullptr, nullptr } 76 | }; 77 | 78 | float Dot3(const FVector4& V1, const FVector4& V2); 79 | float Dot4(const FVector4& V1, const FVector4& V2); 80 | 81 | BEGIN_EXPORT_REFLECTED_CLASS(FVector4) 82 | ADD_EXTERNAL_FUNCTION(float, Dot3, const FVector4&, const FVector4&) 83 | ADD_EXTERNAL_FUNCTION(float, Dot4, const FVector4&, const FVector4&) 84 | ADD_CONST_FUNCTION_EX("Cross", FVector4, operator^, const FVector4&) 85 | ADD_FUNCTION(Size) 86 | ADD_FUNCTION(Size3) 87 | ADD_FUNCTION(SizeSquared) 88 | ADD_FUNCTION(SizeSquared3) 89 | ADD_NAMED_FUNCTION("ToRotator", ToOrientationRotator) 90 | ADD_NAMED_FUNCTION("ToQuat", ToOrientationQuat) 91 | ADD_LIB(FVector4Lib) 92 | END_EXPORT_CLASS() 93 | IMPLEMENT_EXPORTED_CLASS(FVector4) 94 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/ReflectionUtils/EnumDesc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreUObject.h" 18 | #include "Engine/UserDefinedEnum.h" 19 | 20 | /** 21 | * Enum descriptor 22 | */ 23 | class FEnumDesc 24 | { 25 | enum class EType 26 | { 27 | Enum, 28 | UserDefinedEnum, 29 | }; 30 | 31 | public: 32 | explicit FEnumDesc(UEnum *InEnum) 33 | : Enum(InEnum), RefCount(0), Type(EType::Enum) 34 | { 35 | if (Enum) 36 | { 37 | EnumName = Enum->GetName(); 38 | UUserDefinedEnum *UDEnum = Cast(Enum); 39 | Type = UDEnum ? EType::UserDefinedEnum : EType::Enum; 40 | } 41 | } 42 | 43 | ~FEnumDesc() {} 44 | 45 | bool Release() 46 | { 47 | --RefCount; 48 | if (!RefCount) 49 | { 50 | delete this; 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | FORCEINLINE bool IsValid() const { return Enum != nullptr; } 57 | 58 | FORCEINLINE const FString& GetName() const { return EnumName; } 59 | 60 | template 61 | FORCEINLINE int64 GetValue(const CharType *EntryName) const 62 | { 63 | static int64 (*Func[2])(UEnum*, FName) = { FEnumDesc::GetEnumValue, FEnumDesc::GetUserDefinedEnumValue }; 64 | return (Func[(int32)Type])(Enum, FName(EntryName)); 65 | } 66 | 67 | FORCEINLINE UEnum* GetEnum() const { return Enum; } 68 | 69 | FORCEINLINE int32 GetRefCount() const { return RefCount; } 70 | 71 | FORCEINLINE void AddRef() { ++RefCount; } 72 | 73 | static int64 GetEnumValue(UEnum *Enum, FName EntryName) 74 | { 75 | check(Enum); 76 | return Enum->GetValueByName(EntryName); 77 | } 78 | 79 | static int64 GetUserDefinedEnumValue(UEnum *Enum, FName EntryName) 80 | { 81 | check(Enum); 82 | int32 NumEntries = Enum->NumEnums(); 83 | for (int32 i = 0; i < NumEntries; ++i) 84 | { 85 | FName DisplayName(*Enum->GetDisplayNameTextByIndex(i).ToString()); 86 | if (DisplayName == EntryName) 87 | { 88 | return Enum->GetValueByIndex(i); 89 | } 90 | } 91 | return INDEX_NONE; 92 | } 93 | 94 | private: 95 | union 96 | { 97 | UEnum *Enum; 98 | UUserDefinedEnum *UserDefinedEnum; 99 | }; 100 | 101 | FString EnumName; 102 | int32 RefCount; 103 | EType Type; 104 | }; 105 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/ReflectionUtils/FieldDesc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "ClassDesc.h" 18 | 19 | /** 20 | * Field descriptor 21 | */ 22 | class FFieldDesc 23 | { 24 | friend class FClassDesc; 25 | 26 | public: 27 | FORCEINLINE bool IsValid() const { return FieldIndex != 0; } 28 | 29 | FORCEINLINE bool IsProperty() const { return FieldIndex > 0; } 30 | 31 | FORCEINLINE bool IsFunction() const { return FieldIndex < 0; } 32 | 33 | FORCEINLINE bool IsInherited() const { return OuterClass != QueryClass; } 34 | 35 | FORCEINLINE FPropertyDesc* AsProperty() const { return FieldIndex > 0 ? OuterClass->GetProperty(FieldIndex - 1) : nullptr; } 36 | 37 | FORCEINLINE FFunctionDesc* AsFunction() const { return FieldIndex < 0 ? OuterClass->GetFunction(-FieldIndex - 1) : nullptr; } 38 | 39 | FORCEINLINE FString GetOuterName() const { return OuterClass ? OuterClass->GetName() : TEXT(""); } 40 | 41 | private: 42 | FFieldDesc() 43 | : QueryClass(nullptr), OuterClass(nullptr), FieldIndex(0) 44 | {} 45 | 46 | ~FFieldDesc() {} 47 | 48 | FClassDesc *QueryClass; 49 | FClassDesc *OuterClass; 50 | int32 FieldIndex; // index in FClassDesc 51 | }; 52 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/ReflectionUtils/PropertyCreator.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "UnLuaBase.h" 18 | 19 | class FPropertyDesc; 20 | 21 | USTRUCT(noexport) 22 | struct FPropertyCollector 23 | { 24 | }; 25 | 26 | class IPropertyCreator 27 | { 28 | public: 29 | static IPropertyCreator& Instance(); 30 | 31 | virtual void Cleanup() = 0; 32 | virtual TSharedPtr CreateBoolProperty() = 0; 33 | virtual TSharedPtr CreateIntProperty() = 0; 34 | virtual TSharedPtr CreateFloatProperty() = 0; 35 | virtual TSharedPtr CreateStringProperty() = 0; 36 | virtual TSharedPtr CreateNameProperty() = 0; 37 | virtual TSharedPtr CreateTextProperty() = 0; 38 | virtual TSharedPtr CreateEnumProperty(UEnum *Enum) = 0; 39 | virtual TSharedPtr CreateClassProperty(UClass *Class) = 0; 40 | virtual TSharedPtr CreateObjectProperty(UClass *Class) = 0; 41 | virtual TSharedPtr CreateSoftClassProperty(UClass *Class) = 0; 42 | virtual TSharedPtr CreateSoftObjectProperty(UClass *Class) = 0; 43 | virtual TSharedPtr CreateWeakObjectProperty(UClass *Class) = 0; 44 | virtual TSharedPtr CreateLazyObjectProperty(UClass *Class) = 0; 45 | virtual TSharedPtr CreateInterfaceProperty(UClass *Class) = 0; 46 | virtual TSharedPtr CreateStructProperty(UScriptStruct *Struct) = 0; 47 | virtual TSharedPtr CreateProperty(FProperty *TemplateProperty) = 0; 48 | }; 49 | 50 | #define GPropertyCreator IPropertyCreator::Instance() 51 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/ReflectionUtils/ReflectionRegistry.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "EnumDesc.h" 18 | #include "ClassDesc.h" 19 | #include "FunctionDesc.h" 20 | 21 | #define ENABLE_CALL_OVERRIDDEN_FUNCTION 1 // option to call overridden UFunction 22 | 23 | /** 24 | * Reflection registry 25 | */ 26 | class FReflectionRegistry 27 | { 28 | public: 29 | ~FReflectionRegistry() { Cleanup(); } 30 | 31 | void Cleanup(); 32 | 33 | template 34 | FClassDesc* FindClass(const CharType *InName) 35 | { 36 | FClassDesc **ClassDesc = Name2Classes.Find(FName(InName)); 37 | return ClassDesc ? *ClassDesc : nullptr; 38 | } 39 | 40 | bool UnRegisterClass(FClassDesc *ClassDesc); 41 | FClassDesc* RegisterClass(const TCHAR *InName, TArray *OutChain = nullptr); 42 | FClassDesc* RegisterClass(UStruct *InStruct, TArray *OutChain = nullptr); 43 | 44 | bool NotifyUObjectDeleted(const UObjectBase *InObject); 45 | 46 | template 47 | FEnumDesc* FindEnum(const CharType *InName) 48 | { 49 | FEnumDesc **EnumDesc = Enums.Find(FName(InName)); 50 | return EnumDesc ? *EnumDesc : nullptr; 51 | } 52 | 53 | template 54 | bool UnRegisterEnumByName(const CharType *InName) 55 | { 56 | FName Name(InName); 57 | FEnumDesc **EnumDescPtr = Enums.Find(Name); 58 | if (EnumDescPtr) 59 | { 60 | FEnumDesc *EnumDesc = *EnumDescPtr; 61 | if (EnumDesc && EnumDesc->Release()) 62 | { 63 | Enums.Remove(Name); 64 | return true; 65 | } 66 | } 67 | return false; 68 | } 69 | 70 | FEnumDesc* RegisterEnum(const TCHAR *InName); 71 | FEnumDesc* RegisterEnum(UEnum *InEnum); 72 | 73 | FFunctionDesc* RegisterFunction(UFunction *InFunction, int32 InFunctionRef = INDEX_NONE); 74 | bool UnRegisterFunction(UFunction *InFunction); 75 | #if ENABLE_CALL_OVERRIDDEN_FUNCTION 76 | bool AddOverriddenFunction(UFunction *NewFunc, UFunction *OverriddenFunc); 77 | UFunction* RemoveOverriddenFunction(UFunction *NewFunc); 78 | UFunction* FindOverriddenFunction(UFunction *NewFunc); 79 | #endif 80 | 81 | #if UE_BUILD_DEBUG 82 | void Debug() 83 | { 84 | check(true); 85 | } 86 | #endif 87 | 88 | private: 89 | FClassDesc* RegisterClassInternal(const FString &ClassName, UStruct *Struct, FClassDesc::EType Type); 90 | void GetClassChain(FClassDesc *ClassDesc, TArray *OutChain); 91 | 92 | TMap Name2Classes; 93 | TMap Struct2Classes; 94 | TMap NonNativeStruct2Classes; 95 | TMap Enums; 96 | TMap Functions; 97 | #if ENABLE_CALL_OVERRIDDEN_FUNCTION 98 | TMap OverriddenFunctions; 99 | #endif 100 | }; 101 | 102 | extern FReflectionRegistry GReflectionRegistry; 103 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/Tests/UnLuaPerformanceTestProxy.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaPerformanceTestProxy.h" 16 | 17 | void AUnLuaPerformanceTestProxy::NOP() 18 | { 19 | } 20 | 21 | void AUnLuaPerformanceTestProxy::Simulate(float DeltaTime) 22 | { 23 | } 24 | 25 | int32 AUnLuaPerformanceTestProxy::GetMeshID() const 26 | { 27 | return MeshID; 28 | } 29 | 30 | const FString& AUnLuaPerformanceTestProxy::GetMeshName() const 31 | { 32 | return MeshName; 33 | } 34 | 35 | const FVector& AUnLuaPerformanceTestProxy::GetCOM() const 36 | { 37 | return COM; 38 | } 39 | 40 | int32 AUnLuaPerformanceTestProxy::UpdateMeshID(int32 NewID) 41 | { 42 | return NewID; 43 | } 44 | 45 | FString AUnLuaPerformanceTestProxy::UpdateMeshName(const FString &NewName) 46 | { 47 | return NewName; 48 | } 49 | 50 | bool AUnLuaPerformanceTestProxy::Raycast(const FVector &Origin, const FVector &Direction) const 51 | { 52 | return true; 53 | } 54 | 55 | void AUnLuaPerformanceTestProxy::GetIndices(TArray &OutIndices) const 56 | { 57 | } 58 | 59 | void AUnLuaPerformanceTestProxy::UpdateIndices(const TArray &NewIndices) 60 | { 61 | } 62 | 63 | void AUnLuaPerformanceTestProxy::GetPositions(TArray &OutPositions) const 64 | { 65 | } 66 | 67 | void AUnLuaPerformanceTestProxy::UpdatePositions(const TArray &NewPositions) 68 | { 69 | } 70 | 71 | const TArray& AUnLuaPerformanceTestProxy::GetPredictedPositions() const 72 | { 73 | return PredictedPositions; 74 | } 75 | 76 | bool AUnLuaPerformanceTestProxy::GetMeshInfo(int32 &OutMeshID, FString &OutMeshName, FVector &OutCOM, TArray &OutIndices, TArray &OutPositions, TArray &OutPredictedPositions) const 77 | { 78 | return true; 79 | } 80 | 81 | 82 | #if UE_BUILD_TEST 83 | 84 | #include "Misc/DateTime.h" 85 | #include "Misc/FileHelper.h" 86 | #include "UnLuaEx.h" 87 | 88 | bool LogPerformanceData(const FString &Message) 89 | { 90 | FString ProfilingFilePath = FString::Printf(TEXT("%sProfiling/UnLua-Performance-%s.csv"), *FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()), *FDateTime::Now().ToString()); 91 | bool bSuccess = FFileHelper::SaveStringToFile(Message, *ProfilingFilePath); 92 | return bSuccess; 93 | } 94 | 95 | EXPORT_FUNCTION(bool, LogPerformanceData, const FString&) 96 | 97 | EXPORT_FUNCTION_EX(Seconds, double, FPlatformTime::Seconds) 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/Tests/UnLuaPerformanceTestProxy.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "GameFramework/Actor.h" 18 | #include "UnLuaInterface.h" 19 | #include "UnLuaPerformanceTestProxy.generated.h" 20 | 21 | UCLASS() 22 | class AUnLuaPerformanceTestProxy : public AActor, public IUnLuaInterface 23 | { 24 | GENERATED_BODY() 25 | 26 | public: 27 | UFUNCTION(BlueprintCallable) 28 | void NOP(); 29 | 30 | UFUNCTION(BlueprintCallable) 31 | void Simulate(float DeltaTime); 32 | 33 | UFUNCTION(BlueprintCallable) 34 | int32 GetMeshID() const; 35 | 36 | UFUNCTION(BlueprintCallable) 37 | const FString& GetMeshName() const; 38 | 39 | UFUNCTION(BlueprintCallable) 40 | const FVector& GetCOM() const; 41 | 42 | UFUNCTION(BlueprintCallable) 43 | int32 UpdateMeshID(int32 NewID); 44 | 45 | UFUNCTION(BlueprintCallable) 46 | FString UpdateMeshName(const FString &NewName); 47 | 48 | UFUNCTION(BlueprintCallable) 49 | bool Raycast(const FVector &Origin, const FVector &Direction) const; 50 | 51 | UFUNCTION(BlueprintCallable) 52 | void GetIndices(TArray &OutIndices) const; 53 | 54 | UFUNCTION(BlueprintCallable) 55 | void UpdateIndices(const TArray &NewIndices); 56 | 57 | UFUNCTION(BlueprintCallable) 58 | void GetPositions(TArray &OutPositions) const; 59 | 60 | UFUNCTION(BlueprintCallable) 61 | void UpdatePositions(const TArray &NewPositions); 62 | 63 | UFUNCTION(BlueprintCallable) 64 | const TArray& GetPredictedPositions() const; 65 | 66 | UFUNCTION(BlueprintCallable) 67 | bool GetMeshInfo(int32 &OutMeshID, FString &OutMeshName, FVector &OutCOM, TArray &OutIndices, TArray &OutPositions, TArray &OutPredictedPositions) const; 68 | 69 | virtual FString GetModuleName_Implementation() const override 70 | { 71 | return TEXT("UnLuaPerformanceTestProxy"); 72 | } 73 | 74 | private: 75 | UPROPERTY() 76 | int32 MeshID; 77 | 78 | UPROPERTY() 79 | FString MeshName; 80 | 81 | UPROPERTY() 82 | FVector COM; 83 | 84 | UPROPERTY() 85 | TArray Indices; 86 | 87 | UPROPERTY() 88 | TArray Positions; 89 | 90 | UPROPERTY() 91 | TArray PredictedPositions; 92 | }; 93 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/UEObjectReferencer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "Containers/Set.h" 18 | #include "UObject/GCObject.h" 19 | 20 | class FObjectReferencer : public FGCObject 21 | { 22 | public: 23 | static FObjectReferencer& Instance() 24 | { 25 | static FObjectReferencer Referencer; 26 | return Referencer; 27 | } 28 | 29 | void AddObjectRef(UObject *Object) 30 | { 31 | ReferencedObjects.Add(Object); 32 | } 33 | 34 | void RemoveObjectRef(UObject *Object) 35 | { 36 | ReferencedObjects.Remove(Object); 37 | } 38 | 39 | void Cleanup() 40 | { 41 | return ReferencedObjects.Empty(); 42 | } 43 | 44 | #if UE_BUILD_DEBUG 45 | void Debug() 46 | { 47 | check(true); 48 | } 49 | #endif 50 | 51 | virtual void AddReferencedObjects(FReferenceCollector& Collector) override 52 | { 53 | Collector.AddReferencedObjects(ReferencedObjects); 54 | } 55 | 56 | private: 57 | FObjectReferencer() {} 58 | 59 | TSet ReferencedObjects; 60 | }; 61 | 62 | #define GObjectReferencer FObjectReferencer::Instance() 63 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/UnLuaDelegates.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaDelegates.h" 16 | 17 | FUnLuaDelegates::FOnLuaStateCreated FUnLuaDelegates::OnLuaStateCreated; 18 | FUnLuaDelegates::FOnLuaContextInitialized FUnLuaDelegates::OnLuaContextInitialized; 19 | FUnLuaDelegates::FOnLuaContextCleanup FUnLuaDelegates::OnPreLuaContextCleanup; 20 | FUnLuaDelegates::FOnLuaContextCleanup FUnLuaDelegates::OnPostLuaContextCleanup; 21 | FUnLuaDelegates::FOnPreStaticallyExport FUnLuaDelegates::OnPreStaticallyExport; 22 | FUnLuaDelegates::FOnObjectBinded FUnLuaDelegates::OnObjectBinded; 23 | FUnLuaDelegates::FOnObjectUnbinded FUnLuaDelegates::OnObjectUnbinded; 24 | FUnLuaDelegates::FGenericLuaDelegate FUnLuaDelegates::HotfixLua; 25 | FUnLuaDelegates::FGenericLuaDelegate FUnLuaDelegates::ReportLuaCallError; 26 | FUnLuaDelegates::FGenericLuaDelegate FUnLuaDelegates::ConfigureLuaGC; 27 | FUnLuaDelegates::FLuaFileLoader FUnLuaDelegates::LoadLuaFile; 28 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/UnLuaModule.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "Modules/ModuleManager.h" 16 | #include "LuaContext.h" 17 | 18 | #define LOCTEXT_NAMESPACE "FUnLuaModule" 19 | 20 | class FUnLuaModule : public IModuleInterface 21 | { 22 | public: 23 | virtual void StartupModule() override 24 | { 25 | FLuaContext::Create(); 26 | GLuaCxt->RegisterDelegates(); 27 | } 28 | 29 | virtual void ShutdownModule() override 30 | { 31 | } 32 | }; 33 | 34 | #undef LOCTEXT_NAMESPACE 35 | 36 | IMPLEMENT_MODULE(FUnLuaModule, UnLua) 37 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Private/UnLuaPrivate.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreUObject.h" 18 | #include "UnLuaBase.h" 19 | 20 | #define UNLUA_LOGERROR(L, CategoryName, Verbosity, Format, ...) \ 21 | {\ 22 | UE_LOG(CategoryName, Verbosity, Format, ##__VA_ARGS__); \ 23 | luaL_traceback(L, L, "", 0); \ 24 | lua_error(L); \ 25 | } 26 | 27 | #if STATS 28 | DECLARE_STATS_GROUP(TEXT("UnLua"), STATGROUP_UnLua, STATCAT_Advanced); 29 | DECLARE_MEMORY_STAT_EXTERN(TEXT("Lua Memory"), STAT_UnLua_Lua_Memory, STATGROUP_UnLua, /*UNLUA_API*/); 30 | DECLARE_MEMORY_STAT_EXTERN(TEXT("Persistent Parameter Buffer Memory"), STAT_UnLua_PersistentParamBuffer_Memory, STATGROUP_UnLua, /*UNLUA_API*/); 31 | DECLARE_MEMORY_STAT_EXTERN(TEXT("OutParmRec Memory"), STAT_UnLua_OutParmRec_Memory, STATGROUP_UnLua, /*UNLUA_API*/); 32 | #endif 33 | 34 | UNLUA_API bool HotfixLua(); 35 | 36 | UNLUA_API extern FString GLuaSrcRelativePath; 37 | UNLUA_API extern FString GLuaSrcFullPath; 38 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Public/UnLuaDebugBase.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreUObject.h" 18 | #include "UnLuaCompatibility.h" 19 | #include "lua.hpp" 20 | 21 | #define MAX_LUA_VALUE_DEPTH 4 22 | 23 | namespace UnLua 24 | { 25 | 26 | /** 27 | * Helper to hold a Lua value 28 | */ 29 | struct UNLUA_API FLuaDebugValue 30 | { 31 | FLuaDebugValue() 32 | : Depth(INDEX_NONE), bAlreadyBuilt(false) 33 | {} 34 | 35 | FString ToString() const; 36 | 37 | /** 38 | * Fill in this value 39 | * 40 | * @param Index - Lua stack index 41 | * @param Level - the depth of the variable's value 42 | */ 43 | void Build(lua_State *L, int32 Index, int32 Level = MAX_int32); 44 | 45 | FString ReadableValue; 46 | FString Type; 47 | int32 Depth; 48 | bool bAlreadyBuilt; 49 | TArray Keys; 50 | TArray Values; 51 | 52 | private: 53 | FLuaDebugValue* AddKey(); 54 | FLuaDebugValue* AddValue(); 55 | 56 | UObjectBaseUtility* GetContainerObject(UStruct *Struct, void *ContainerPtr); 57 | void BuildFromUserdata(lua_State *L, int32 Index); 58 | void BuildFromUStruct(UStruct *Struct, void *ContainerPtr, UObjectBaseUtility *ContainerObject = nullptr); 59 | void BuildFromTArray(FScriptArrayHelper &ArrayHelper, const FProperty *InnerProperty); 60 | void BuildFromTMap(FScriptMapHelper &MapHelper); 61 | void BuildFromTSet(FScriptSetHelper &SetHelper); 62 | void BuildFromUProperty(const FProperty *Property, void *ValuePtr); 63 | }; 64 | 65 | /** 66 | * Lua variable wrapper 67 | */ 68 | struct FLuaVariable 69 | { 70 | FString Key; 71 | FLuaDebugValue Value; 72 | }; 73 | 74 | 75 | /** 76 | * Get local variables and upvalues of the runtime stack 77 | * 78 | * @param StackLevel - stack level. level 0 is the current running function, whereas level n+1 is the function that has called level n 79 | * @param[out] LocalVariables - local variables 80 | * @param[out] Upvalues - upvalues 81 | * @param Level - the depth of the variable's value 82 | * @return - true if successful, false otherwise 83 | */ 84 | UNLUA_API bool GetStackVariables(lua_State *L, int32 StackLevel, TArray &LocalVariables, TArray &Upvalues, int32 Level = MAX_int32); 85 | 86 | /** 87 | * Get call stack 88 | * 89 | * @return - full description 90 | */ 91 | UNLUA_API FString GetLuaCallStack(lua_State *L); 92 | 93 | } // namespace UnLua 94 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Public/UnLuaDelegates.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "CoreMinimal.h" 18 | 19 | struct lua_State; 20 | 21 | class UNLUA_API FUnLuaDelegates 22 | { 23 | public: 24 | DECLARE_MULTICAST_DELEGATE_OneParam(FOnLuaStateCreated, lua_State*); 25 | DECLARE_MULTICAST_DELEGATE(FOnLuaContextInitialized); 26 | DECLARE_MULTICAST_DELEGATE(FOnPreStaticallyExport); 27 | DECLARE_MULTICAST_DELEGATE_OneParam(FOnLuaContextCleanup, bool); 28 | 29 | DECLARE_MULTICAST_DELEGATE_OneParam(FOnObjectBinded, UObjectBaseUtility*); 30 | DECLARE_MULTICAST_DELEGATE_OneParam(FOnObjectUnbinded, UObjectBaseUtility*); 31 | 32 | DECLARE_DELEGATE_RetVal_OneParam(int32, FGenericLuaDelegate, lua_State*); 33 | DECLARE_DELEGATE_RetVal_TwoParams(bool, FLuaFileLoader, const FString&, TArray&); 34 | 35 | static FOnLuaStateCreated OnLuaStateCreated; 36 | static FOnLuaContextInitialized OnLuaContextInitialized; 37 | static FOnLuaContextCleanup OnPreLuaContextCleanup; 38 | static FOnLuaContextCleanup OnPostLuaContextCleanup; 39 | static FOnPreStaticallyExport OnPreStaticallyExport; 40 | 41 | static FOnObjectBinded OnObjectBinded; 42 | static FOnObjectUnbinded OnObjectUnbinded; 43 | 44 | static FGenericLuaDelegate HotfixLua; 45 | static FGenericLuaDelegate ReportLuaCallError; 46 | static FGenericLuaDelegate ConfigureLuaGC; 47 | 48 | static FLuaFileLoader LoadLuaFile; 49 | }; 50 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/Public/UnLuaInterface.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "UObject/Interface.h" 18 | #include "UnLuaInterface.generated.h" 19 | 20 | /** 21 | * Interface for binding UCLASS and Lua module 22 | */ 23 | UINTERFACE() 24 | class UNLUA_API UUnLuaInterface : public UInterface 25 | { 26 | GENERATED_BODY() 27 | }; 28 | 29 | class UNLUA_API IUnLuaInterface 30 | { 31 | GENERATED_BODY() 32 | 33 | public: 34 | /** 35 | * return a Lua file path which is relative to project's 'Content/Script', for example 'Weapon.BP_DefaultProjectile_C' 36 | */ 37 | UFUNCTION(BlueprintNativeEvent) 38 | FString GetModuleName() const; 39 | }; 40 | -------------------------------------------------------------------------------- /UnLua/Source/UnLua/UnLua.Build.cs: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | using System.IO; 16 | using UnrealBuildTool; 17 | 18 | public class UnLua : ModuleRules 19 | { 20 | public UnLua(ReadOnlyTargetRules Target) : base(Target) 21 | { 22 | bEnforceIWYU = false; 23 | 24 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 25 | 26 | PublicIncludePaths.AddRange( 27 | new string[] { 28 | } 29 | ); 30 | 31 | 32 | PrivateIncludePaths.AddRange( 33 | new string[] { 34 | "UnLua/Private", 35 | } 36 | ); 37 | 38 | 39 | PublicIncludePathModuleNames.AddRange( 40 | new string[] { 41 | "ApplicationCore", 42 | } 43 | ); 44 | 45 | 46 | PrivateDependencyModuleNames.AddRange( 47 | new string[] 48 | { 49 | "Core", 50 | "CoreUObject", 51 | "Engine", 52 | "Slate", 53 | "InputCore", 54 | "Projects", 55 | "Lua", 56 | "LibLuasocket", 57 | "LibLuacrypt", 58 | "LibLpeg", 59 | "LibSproto", 60 | "LibCjson" 61 | } 62 | ); 63 | 64 | 65 | if (Target.bBuildEditor == true) 66 | { 67 | PrivateDependencyModuleNames.Add("UnrealEd"); 68 | } 69 | 70 | bool bAutoStartup = true; 71 | if (bAutoStartup) 72 | { 73 | PublicDefinitions.Add("AUTO_UNLUA_STARTUP=1"); 74 | } 75 | 76 | bool bWithUE4Namespace = false; 77 | if (bWithUE4Namespace) 78 | { 79 | PublicDefinitions.Add("WITH_UE4_NAMESPACE=1"); 80 | } 81 | 82 | bool bSupportsRpcCall = false; 83 | if (bSupportsRpcCall) 84 | { 85 | PublicDefinitions.Add("SUPPORTS_RPC_CALL=1"); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaDefaultParamCollector/UnLuaDefaultParamCollector.Build.cs: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | using UnrealBuildTool; 16 | using System.IO; 17 | 18 | namespace UnrealBuildTool.Rules 19 | { 20 | public class UnLuaDefaultParamCollector : ModuleRules 21 | { 22 | public UnLuaDefaultParamCollector(ReadOnlyTargetRules Target) : base(Target) 23 | { 24 | bEnforceIWYU = false; 25 | 26 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 27 | 28 | PublicIncludePaths.AddRange( 29 | new string[] { 30 | "Programs/UnrealHeaderTool/Public", 31 | } 32 | ); 33 | 34 | 35 | PrivateIncludePaths.AddRange( 36 | new string[] { 37 | "UnLuaDefaultParamCollector/Private", 38 | "UnLua/Private", 39 | } 40 | ); 41 | 42 | 43 | PrivateDependencyModuleNames.AddRange( 44 | new string[] 45 | { 46 | "Core", 47 | "CoreUObject", 48 | } 49 | ); 50 | 51 | PublicDefinitions.Add("HACK_HEADER_GENERATOR=1"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Classes/Commandlets/UnLuaIntelliSenseCommandlet.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "Commandlets/Commandlet.h" 16 | #include "UnLuaIntelliSenseCommandlet.generated.h" 17 | 18 | UCLASS() 19 | class UUnLuaIntelliSenseCommandlet : public UCommandlet 20 | { 21 | GENERATED_UCLASS_BODY() 22 | 23 | public: 24 | virtual int32 Main(const FString& Params) override; 25 | 26 | private: 27 | void SaveFile(const FString &ModuleName, const FString &FileName, const FString &GeneratedFileContent); 28 | 29 | class FLuaContext *Context; 30 | FString IntermediateDir; 31 | }; 32 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Private/UnLuaEditorCommands.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEditorCommands.h" 16 | 17 | #define LOCTEXT_NAMESPACE "FUnLuaEditorCommands" 18 | 19 | void FUnLuaEditorCommands::RegisterCommands() 20 | { 21 | UI_COMMAND(CreateLuaTemplate, "Lua Template", "Create lua template file", EUserInterfaceActionType::Button, FInputChord()); 22 | UI_COMMAND(HotfixLua, "Lua Hotfix", "Hotfix lua", EUserInterfaceActionType::Button, FInputChord(TEXT("L"), false, true, false, false)); 23 | } 24 | 25 | #undef LOCTEXT_NAMESPACE 26 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Private/UnLuaEditorCommands.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "Framework/Commands/Commands.h" 18 | 19 | class FUnLuaEditorCommands : public TCommands 20 | { 21 | public: 22 | FUnLuaEditorCommands() 23 | : TCommands(TEXT("UnLuaEditor"), NSLOCTEXT("Contexts", "UnLuaEditor", "UnLua Editor"), NAME_None, "UnLuaEditorStyle") 24 | { 25 | } 26 | 27 | virtual void RegisterCommands() override; 28 | 29 | TSharedPtr CreateLuaTemplate; 30 | TSharedPtr HotfixLua; 31 | }; 32 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Private/UnLuaEditorCore.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaPrivate.h" 16 | #include "Misc/FileHelper.h" 17 | #include "Engine/Blueprint.h" 18 | #include "Blueprint/UserWidget.h" 19 | #include "Animation/AnimInstance.h" 20 | #include "GameFramework/Actor.h" 21 | #include "Interfaces/IPluginManager.h" 22 | 23 | // create Lua template file for the selected blueprint 24 | bool CreateLuaTemplateFile(UBlueprint *Blueprint) 25 | { 26 | if (Blueprint) 27 | { 28 | UClass *Class = Blueprint->GeneratedClass; 29 | FString ClassName = Class->GetName(); 30 | FString OuterPath = Class->GetPathName(); 31 | int32 LastIndex; 32 | if (OuterPath.FindLastChar('/', LastIndex)) 33 | { 34 | OuterPath = OuterPath.Left(LastIndex + 1); 35 | } 36 | OuterPath = OuterPath.RightChop(6); // ignore "/Game/" 37 | FString FileName = FString::Printf(TEXT("%s%s%s.lua"), *GLuaSrcFullPath, *OuterPath, *ClassName); 38 | if (FPaths::FileExists(FileName)) 39 | { 40 | UE_LOG(LogUnLua, Warning, TEXT("Lua file (%s) is already existed!"), *ClassName); 41 | return false; 42 | } 43 | 44 | static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("UnLua"))->GetContentDir(); 45 | 46 | FString TemplateName; 47 | if (Class->IsChildOf(AActor::StaticClass())) 48 | { 49 | // default BlueprintEvents for Actor 50 | TemplateName = ContentDir + TEXT("/ActorTemplate.lua"); 51 | } 52 | else if (Class->IsChildOf(UUserWidget::StaticClass())) 53 | { 54 | // default BlueprintEvents for UserWidget (UMG) 55 | TemplateName = ContentDir + TEXT("/UserWidgetTemplate.lua"); 56 | } 57 | else if (Class->IsChildOf(UAnimInstance::StaticClass())) 58 | { 59 | // default BlueprintEvents for AnimInstance (animation blueprint) 60 | TemplateName = ContentDir + TEXT("/AnimInstanceTemplate.lua"); 61 | } 62 | else if (Class->IsChildOf(UActorComponent::StaticClass())) 63 | { 64 | // default BlueprintEvents for ActorComponent 65 | TemplateName = ContentDir + TEXT("/ActorComponentTemplate.lua"); 66 | } 67 | 68 | FString Content; 69 | FFileHelper::LoadFileToString(Content, *TemplateName); 70 | Content = Content.Replace(TEXT("TemplateName"), *ClassName); 71 | 72 | return FFileHelper::SaveStringToFile(Content, *FileName); 73 | } 74 | return false; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Private/UnLuaEditorStyle.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #include "UnLuaEditorStyle.h" 16 | #include "Interfaces/IPluginManager.h" 17 | #include "Styling/SlateStyleRegistry.h" 18 | 19 | #define IMAGE_BRUSH(RelativePath, ...) FSlateImageBrush(RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__) 20 | #define BOX_BRUSH(RelativePath, ...) FSlateBoxBrush(RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__) 21 | #define BORDER_BRUSH(RelativePath, ...) FSlateBorderBrush(RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__) 22 | #define TTF_FONT(RelativePath, ...) FSlateFontInfo(RootToContentDir(RelativePath, TEXT(".ttf")), __VA_ARGS__) 23 | #define OTF_FONT(RelativePath, ...) FSlateFontInfo(RootToContentDir(RelativePath, TEXT(".otf")), __VA_ARGS__) 24 | 25 | FUnLuaEditorStyle::FUnLuaEditorStyle() 26 | : FSlateStyleSet("UnLuaEditorStyle") 27 | { 28 | const FVector2D Icon40x40(40.0f, 40.0f); 29 | 30 | SetContentRoot(IPluginManager::Get().FindPlugin("UnLua")->GetBaseDir() / TEXT("Resources")); 31 | 32 | Set("UnLuaEditor.CreateLuaTemplate", new IMAGE_BRUSH("icon_luatemplate_40x", Icon40x40)); 33 | 34 | FSlateStyleRegistry::RegisterSlateStyle(*this); 35 | } 36 | 37 | FUnLuaEditorStyle::~FUnLuaEditorStyle() 38 | { 39 | FSlateStyleRegistry::UnRegisterSlateStyle(*this); 40 | } 41 | 42 | #undef IMAGE_BRUSH 43 | #undef BOX_BRUSH 44 | #undef BORDER_BRUSH 45 | #undef TTF_FONT 46 | #undef OTF_FONT 47 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/Private/UnLuaEditorStyle.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "Styling/SlateStyle.h" 18 | 19 | class FUnLuaEditorStyle : public FSlateStyleSet 20 | { 21 | public: 22 | FUnLuaEditorStyle(); 23 | ~FUnLuaEditorStyle(); 24 | }; 25 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaEditor/UnLuaEditor.Build.cs: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | using UnrealBuildTool; 16 | using System.IO; 17 | 18 | public class UnLuaEditor : ModuleRules 19 | { 20 | public UnLuaEditor(ReadOnlyTargetRules Target) : base(Target) 21 | { 22 | bEnforceIWYU = false; 23 | 24 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 25 | 26 | PublicIncludePaths.AddRange( 27 | new string[] { 28 | } 29 | ); 30 | 31 | 32 | string EngineDir = Path.GetFullPath(Target.RelativeEnginePath); 33 | PrivateIncludePaths.AddRange( 34 | new string[] { 35 | "UnLuaEditor/Private", 36 | "UnLua/Private", 37 | Path.Combine(EngineDir, @"Source/Editor/AnimationBlueprintEditor/Private"), 38 | } 39 | ); 40 | 41 | 42 | PrivateIncludePathModuleNames.AddRange( 43 | new string[] 44 | { 45 | "Kismet", 46 | "MainFrame", 47 | "AnimationBlueprintEditor", 48 | "Persona", 49 | } 50 | ); 51 | 52 | 53 | PrivateDependencyModuleNames.AddRange( 54 | new string[] 55 | { 56 | "Core", 57 | "CoreUObject", 58 | "Engine", 59 | "UnrealEd", 60 | "Projects", 61 | "InputCore", 62 | "UMG", 63 | "Slate", 64 | "SlateCore", 65 | "UnLua" 66 | } 67 | ); 68 | 69 | 70 | DynamicallyLoadedModuleNames.AddRange( 71 | new string[] 72 | { 73 | "Kismet", 74 | "MainFrame", 75 | "AnimationBlueprintEditor", 76 | } 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /UnLua/Source/UnLuaIntelliSense/UnLuaIntelliSense.Build.cs: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making UnLua available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); 6 | // you may not use this file except in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and limitations under the License. 14 | 15 | using UnrealBuildTool; 16 | using System.IO; 17 | 18 | namespace UnrealBuildTool.Rules 19 | { 20 | public class UnLuaIntelliSense : ModuleRules 21 | { 22 | public UnLuaIntelliSense(ReadOnlyTargetRules Target) : base(Target) 23 | { 24 | bEnforceIWYU = false; 25 | 26 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 27 | 28 | PublicIncludePaths.AddRange( 29 | new string[] { 30 | "Programs/UnrealHeaderTool/Public", 31 | } 32 | ); 33 | 34 | 35 | PrivateIncludePaths.AddRange( 36 | new string[] { 37 | "UnLuaIntelliSense/Private", 38 | "UnLua/Private", 39 | } 40 | ); 41 | 42 | 43 | PrivateDependencyModuleNames.AddRange( 44 | new string[] 45 | { 46 | "Core", 47 | "CoreUObject", 48 | } 49 | ); 50 | 51 | PublicDefinitions.Add("ENABLE_INTELLISENSE=1"); 52 | 53 | PublicDefinitions.Add("HACK_HEADER_GENERATOR=1"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /UnLua/UnLua.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "UnLua", 6 | "Description": "Lua scripting plugin", 7 | "Category": "Scripting", 8 | "CreatedBy": "Tencent", 9 | "CreatedByURL": "https://www.tencent.com/", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "Installed": false, 16 | "CanBeUsedWithUnrealHeaderTool": true, 17 | "EnabledByDefault":true, 18 | "Modules": 19 | [ 20 | { 21 | "Name" : "UnLua", 22 | "Type" : "Runtime", 23 | "LoadingPhase" : "PostConfigInit", 24 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 25 | }, 26 | { 27 | "Name" : "UnLuaEditor", 28 | "Type" : "Editor", 29 | "LoadingPhase" : "Default", 30 | "WhitelistPlatforms" : [ "Win64", "Mac" ] 31 | }, 32 | { 33 | "Name" : "UnLuaDefaultParamCollector", 34 | "Type" : "Program", 35 | "LoadingPhase" : "PostConfigInit" 36 | }, 37 | { 38 | "Name" : "UnLuaIntelliSense", 39 | "Type" : "Program", 40 | "LoadingPhase" : "PostConfigInit" 41 | }, 42 | { 43 | "Name": "LibLuasocket", 44 | "Type": "Runtime", 45 | "LoadingPhase": "Default", 46 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 47 | }, 48 | { 49 | "Name": "LibLuacrypt", 50 | "Type": "Runtime", 51 | "LoadingPhase": "Default", 52 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 53 | }, 54 | { 55 | "Name": "LibLpeg", 56 | "Type": "Runtime", 57 | "LoadingPhase": "Default", 58 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 59 | }, 60 | { 61 | "Name": "LibSproto", 62 | "Type": "Runtime", 63 | "LoadingPhase": "Default", 64 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 65 | }, 66 | { 67 | "Name": "LibCjson", 68 | "Type": "Runtime", 69 | "LoadingPhase": "Default", 70 | "WhitelistPlatforms" : [ "Win64", "Mac", "IOS", "Android" ] 71 | } 72 | ] 73 | } 74 | --------------------------------------------------------------------------------