当前位置: 首页 > news >正文

Unity开发游戏使用XLua的基础

Unity使用Xlua的常用编码方式,做一下记录

1、C#调用lua

1、Lua解析器

private LuaEnv env = new LuaEnv();//保持它的唯一性void Start(){env.DoString("print('你好lua')");//env.DoString("require('Main')");  默认在resources文件夹下面//帮助我们清除lua中我们没有手动释放的对象  垃圾回收env.Tick();//销毁lua解释器,用的较少env.Dispose();}

2、自定义loader

    private void Start(){//xlua路径重定向方法_env.AddLoader(MyLoader);_env.DoString("require('Main')");}private byte[] MyLoader(ref string filepath){//传入的filepath是 require执行的lua脚本文件名,在这里是mainstring path = Application.dataPath + "/Lua/" + filepath + ".lua";//判断文件是否存在if (File.Exists(path)){return File.ReadAllBytes(path);}else{Debug.Log("重定向失败,文件名为"+filepath);}return null;}

3、Lua管理器

/// <summary>
/// lua管理器
/// 提供lua解析器
/// 保证解析器的唯一性
/// </summary>
public class LuaMgr
{private static LuaMgr _instance;public static LuaMgr Instance{get{if (_instance==null){_instance = new LuaMgr();}return _instance;}}private LuaEnv _luaEnv;/// <summary>/// 得到lua中的_G/// </summary>public LuaTable Gloabl => _luaEnv.Global;/// <summary>/// 初始化/// </summary>public void Init(){if (_luaEnv!=null) return;_luaEnv = new LuaEnv();_luaEnv.AddLoader(MyLoader);_luaEnv.AddLoader(MyABLoader);}#region 标准内容/// <summary>/// 传入文件名,执行脚本/// </summary>/// <param name="fileName"></param>public void DoLuaFile(string fileName){string str = $"require('{fileName}')";DoString(str);}public void DoString(string str){if(_luaEnv==null){Debug.Log("解析器未初始化");return;}_luaEnv.DoString(str);}/// <summary>/// 释放lua垃圾/// </summary>public void Tick(){if(_luaEnv==null){Debug.Log("解析器未初始化");return;}_luaEnv.Tick();}/// <summary>/// 销毁解析器/// </summary>public void Dispose(){if(_luaEnv==null){Debug.Log("解析器未初始化");return;}_luaEnv.Dispose();_luaEnv = null;}//自动执行private byte[] MyLoader(ref string filepath){//传入的filepath是 require执行的lua脚本文件名,在这里是mainstring path = Application.dataPath + "/Lua/" + filepath + ".lua";//判断文件是否存在if (File.Exists(path)){return File.ReadAllBytes(path);}else{Debug.Log("重定向失败,文件名为"+filepath);}return null;}//重定向加载AB包中的lua脚本private byte[] MyABLoader(ref string filepath){//加载路径string path = Application.streamingAssetsPath + "/lua";//加载AB包AssetBundle ab=AssetBundle.LoadFromFile(path); TextAsset tx = ab.LoadAsset<TextAsset>(filepath+".lua");//加载Lua文件返回//加载lua文件,byte数组return tx.bytes;}//Lua脚本最终会放在ab包中,#endregion
}

4、全局变量获取

 private void Start(){LuaMgr.Instance.Init();LuaMgr.Instance.DoLuaFile("Main");int i= LuaMgr.Instance.Gloabl.Get<int>("testNumber");var i2= LuaMgr.Instance.Gloabl.Get<bool>("testBool");var i3= LuaMgr.Instance.Gloabl.Get<float>("testFloat");var i4= LuaMgr.Instance.Gloabl.Get<string>("testString");//值拷贝不会修改lua中的值,可以用setLuaMgr.Instance.Gloabl.Set("testNumber",1000);i= LuaMgr.Instance.Gloabl.Get<int>("testNumber");Debug.Log("testNumber"+i);}

虽然lua中只有number一种数值类型,但是我们可以根据它具体的值,用对应的C#变量类型来存储

5、全局函数的获取

public delegate void CustomCall();
public delegate void CustomCall2(int a);
//加一个特性,只有添加特性才能被调用,,加完特性后还要一部分工作,就是点击Xlua->Generatedate
[CSharpCallLua]
public delegate int CustomCall3(int a);
[CSharpCallLua]   //使用out来接
public delegate int CustomCall4(int a,out int b,out bool c,out string d,out int e);[CSharpCallLua]   //使用ref来接
public delegate int CustomCall5(int a,ref int b,ref bool c,ref string d,ref int e);//变长函数,如果边长函数中类型多种多样,那就使用object
[CSharpCallLua]
public delegate void CustomCall6(string a,params int[] args);
public class Lesson5_CallFunction : MonoBehaviour
{ void Start(){LuaMgr.Instance.Init();// LuaMgr.Instance.DoString("require('Main')"); LuaMgr.Instance.DoLuaFile("Main");//无参无返回值var call1= LuaMgr.Instance.Gloabl.Get<UnityAction>("testFun1");call1();//有参有返回值var call2 = LuaMgr.Instance.Gloabl.Get<CustomCall3>("testFun2");// Debug.Log(call2(2));var call3 = LuaMgr.Instance.Gloabl.Get<Func<int,int>>("testFun2");// Debug.Log("Func: "+call3(2));//有参多返回值var call4 = LuaMgr.Instance.Gloabl.Get<CustomCall4>("testFun3");int b;bool c;string d;int e;//  Debug.Log(call4(51,out b,out c,out d,out e));var call5 = LuaMgr.Instance.Gloabl.Get<CustomCall5>("testFun3");int b1 = 0;bool c1 = true;string d1="";int e1=0;// Debug.Log(call5(51,ref b1,ref c1,ref d1,ref e1));var call6 = LuaMgr.Instance.Gloabl.Get<CustomCall6>("testFun4");call6("你好",1,5,6,5,4);// LuaFunction lf = LuaMgr.Instance.Gloabl.Get<LuaFunction>("testFun4");// lf.Call("你好", 1, 5, 6, 5, 4);}
print("Variable启动")
-- 无参无返回
testFun1 = function()print("无参无返回")
end-- 有参有返回
testFun2 = function(a)print("有参有返回")return a + 1
end
-- 多返回
testFun3 = function(a)print("多返回")return 1, 2, false, "123", a
end
-- 变长参数
testFun4 = function(a, ...)print("变长参数")print(a)arg = { ... }for k, v in pairs(arg) doprint(k, v)end
end

6、List和Dictionary

 private void Start(){LuaMgr.Instance.Init();LuaMgr.Instance.DoLuaFile("Main");#region ListList<int> list = LuaMgr.Instance.Gloabl.Get<List<int>>("testList");for (int i = 0; i < list.Count; i++){Debug.Log("----"+list[i]);}//不确定类型用objectList<object> list2 = LuaMgr.Instance.Gloabl.Get<List<object>>("testList2");for (int i = 0; i < list2.Count; i++){Debug.Log("----"+list2[i]);}#endregion#region 字典Dictionary<string, int> dic = LuaMgr.Instance.Gloabl.Get<Dictionary<string, int>>("testDic");foreach (var item in dic){Debug.Log(item.Key+"____"+item.Value);}Dictionary<object, object> dic2 = LuaMgr.Instance.Gloabl.Get<Dictionary<object, object>>("testDic2");foreach (var item in dic2){Debug.Log(item.Key+"____"+item.Value);}#endregion}

7、类映射table

//Lua
testClas={testInt=2,testBool=true,testFloat=1.2,testString="123",testFun=function()print("NIHAO")end
}
//C#
public class CallLuaClass
{//在类中去生命成员变量,名字要和lua那边一样//注意,。一定是公有的,不然不能赋值。//这个自定义中的变量可以多也可以少public int testInt;public bool testBool;public float testFloat;public string testString;public UnityAction testFun;//方法
}
public class Lesson7_Table : MonoBehaviour
{private void Start(){LuaMgr.Instance.Init();LuaMgr.Instance.DoLuaFile("Main");CallLuaClass callLuaClass = LuaMgr.Instance.Gloabl.Get<CallLuaClass>("testClas");Debug.Log(callLuaClass.testString);callLuaClass.testFun();}
}

8、接口映射table

注意接口是引用拷贝。改了值后,lua值也会改变

//接口中不允许有成员变量
//我们用属性
[CSharpCallLua]
public interface ICSharpCallInterface
{int testInt { get; set; }bool testBool { get; set; }float testFloat { get; set; }string testString { get; set; }UnityAction testFun { get; set; }
}public class Lesson_Interface : MonoBehaviour
{void Start(){LuaMgr.Instance.Init();LuaMgr.Instance.DoLuaFile("Main");ICSharpCallInterface callInterface = LuaMgr.Instance.Gloabl.Get<ICSharpCallInterface>("testClas");Debug.Log(callInterface.testFloat);}   
}

9、luatable映射到table

    //不过官方不建议使用luaTable和luaFunctionvoid Start(){LuaMgr.Instance.Init();LuaMgr.Instance.DoLuaFile("Main");LuaTable table = LuaMgr.Instance.Gloabl.Get<LuaTable>("testClas");Debug.Log(table.Get<int>("testInt"));table.Get<LuaFunction>("testFun").Call();table.Dispose();//使用完了dispose }

2、lua调用C#(重点)

用的较多。

1、Lua使用C#类

print("************Lua调用C#相关知识点*************")
-- lua中使用C#的类非常简单
-- 固定套路
-- Cs.命名空间.类名
-- Unity的类,比如GameObject Transform等等  ---CS.UnityEngine.类名-- 通过C#中的类,实例化一个对象,注意lua中没有new
-- 默认调用的相当于无参构造
local obj1 = CS.UnityEngine.GameObject()
local obj2 = CS.UnityEngine.GameObject("郑毅")-- 为了方便使用,并且节约性能,定义全局变量储存C#中的类
-- 相当于取了一个别名,这也是一种优化方式
GameObject = CS.UnityEngine.GameObject
local obj3 = GameObject("第三个")-- 类中的静态对象可以直接使用 .来调用
local obj4 = GameObject.Find("郑毅")
--得到对象中的成员变量,直接对象.就可以了
print(obj4.transform.position)
Vector3 = CS.UnityEngine.Vector3;
--使用对象中的成员方法,一定要加:
obj4.transform:Translate(Vector3.right)
print(obj4.transform.position)-- 调用自定义的类
local t = CS.Test()
t:Speak("你好")
--有命名空间的
local t = CS.MyClass.Test2()
t:Speak("你好")--继承mono的类
--继承mono的类是不能直接new的
--lua不支持使用无惨的泛型的
local obj5 = GameObject("加脚本测试")
-- Xlua提供了一个重要防范typeof 可以得到类的类型
obj5:AddComponent(typeof(CS.LuaCallC))

---- c#

public class Test
{public void Speak(string str){Debug.Log("test1"+str);}
}namespace MyClass
{public class Test2{public void Speak(string str){Debug.Log("test2"+str);}}
}
public class LuaCallC : MonoBehaviour
{}

2、枚举

PrimitiveType = CS.UnityEngine.PrimitiveType
GameObject = CS.UnityEngine.GameObject
local obj = GameObject.CreatePrimitive(PrimitiveType.Cube)---获取自定义美剧
myEnum=CS.MyEnum
local c=myEnum.Idle
print(c)
--枚举转换
--数值转枚举
local a=myEnum.__CastFrom(1)
print(a)
--字符串转枚举
local b=myEnum.__CastFrom("Atk ")
print(b)

3、调用C#数组和list和字典

public class Lesson
{public int[] array = new int[5] { 1, 2, 3, 4, 5 };public List<int> list = new List<int>();public Dictionary<int, string> dic = new Dictionary<int, string>();
}
local obj = CS.Lesson()
-- Lua使用数组相关知识
-- 长度
print(obj.array.Length)
print(obj.array[2])
--遍历,虽然lua索引是从1开始
--但是要按照C#来,从0开始
for i = 0, obj.array.Length - 1 doprint(obj.array[i])
end--创建数组   数组的底层是array类,使用静态方法CreateInstance
local array2 = CS.System.Array.CreateInstance(typeof(CS.System.Int32), 10)
print(array2.Length)---list
obj.list:Add(10)
obj.list:Add(20)
obj.list:Add(30)
obj.list:Add(40)for i = 0, obj.list.Count - 1 doprint(obj.list[i])
end
--创建list  相当于得到一个List<int>的一个类的别名,需要再实例化
local list_string = CS.System.Collections.Generic.List(CS.System.Int32)
local list3 = list_string()
list3:Add(50)
print(list3.Count)
print(list3[0])--- 字典
obj.dic:Add(1, "你好")
print(obj.dic[1])for k, v in pairs(obj.dic) doprint(k, v)
end--创建字典
local dicString=CS.System.Collections.Generic.Dictionary(CS.System.String,CS.UnityEngine.Vector3)
local dic2=dicString()
dic2:Add("001",CS.UnityEngine.Vector3.right)print(dic2["001"])---这里有个坑,自己创建的字典,这样是访问不到的
print(dic2:get_Item("001")) --只有通过这种方法才可以
dic2:set_Item("001",CS.UnityEngine.Vector3.up)
print(dic2:get_Item("001")) --只有通过这种方法才可以
print(dic2:TryGetValue("001"))--多返回值

4、拓展方法

//拓展方法
//拓展方法的写法
//想要在lua中使用拓展方法,一定要在工具类前面加上特性
//如果不加该特性,除了拓展方法以外,都不会报错
//但是lua是通过反射机制去调用C#类的,效率较低
//加上可提高性能
[LuaCallCSharp]
public static class Tools
{public static void Move(this Lesson4 obj){Debug.Log(obj.name+"移动");}
}
public class Lesson4
{public string name = "名称";public void Speak(string str){Debug.Log(str);}public static void Eat(){Debug.Log("吃东西");}
}
public class LuaCallC : MonoBehaviour
{private void Start(){Lesson4 lesson4 = new Lesson4();lesson4.Move();//拓展方法,对象可以直接调用}
}
Lesson4 = CS.Lesson4
Lesson4.Eat()
--成员方法
local a = Lesson4()
a:Speak("说话了啊")
--使用拓展方法
a:Move()

5、ref out

public class Lesson5
{public int RefFun(int a,ref int b,ref int c,int d){b = a + d;c = a - d;return 100;}public int OutFun(int a,out int b,out int c,int d){b = a;c = d;return 200;}public int RefOutFun(int a,out int b,ref int c){b = a * 10;c = a * 20;return 300;}
}
Lesson5 = CS.Lesson5
local obj = Lesson5()--ref 参数会以多返回值的形式返回给lua
local a, b, c = obj:RefFun(1, 0, 0, 1)
print(a)
print(b)
print(c)--out 参数会以多返回值的形式返回给lua
--out参数不需要传占位置的值
local a, b, c = obj:OutFun(1, 30)
print(a)
print(b)
print(c)--综合起来
-- out不用占位值 ref需要占位
local a, b, c = obj:OutFun(1, 30)
print(a)
print(b)
print(c)

6、C#函数重载

public class Lesson6
{public int Cal(){return 100;}public int Cal(int a,int b){return a + b;}public int Cal(int a){return a;}public float Cal(float a){return a;}
}
Lesson6 = CS.Lesson6
local obj = Lesson6()print(obj:Cal())
print(obj:Cal(1))
print(obj:Cal(15,20))
--对于C#中多精度的重载函数支持不好
print(obj:Cal(1.25))--如果要解决重载函数模糊不清的问题
--xlua提供了解决方案,反射机制,但这种方法只做了解
--另外,能不用就不用
local m2 = typeof(CS.Lesson6):GetMethod("Cal", { typeof(CS.System.Single) })
--通过xlua提供的一个方法,把它转换成lua函数来使用。
--一般我们转一次,然后重复使用
local f2 = xlua.tofunction(m2)
print(f2(obj,10.2))

7、委托 事件

public class Lesson8
{public UnityAction del;public event UnityAction eventAction;public void DoEvent(){if (eventAction != null) eventAction();}
}
Lesson8 = CS.Lesson8
local obj = Lesson8()-- 委托
local func=function()print("这是lua函数")
end
-- 注意lua没有复合运算符,没有+=
-- 如果第一次往委托中加函数,因为是niu 不能直接+
-- 所以第一次  要先等=
obj.del=func
--第二次可以
obj.del=obj.del+func
obj.del()
--委托清除
obj.del=nil---事件,事件和委托特别不一样
---有点类似于成员方法 
obj:eventAction("+",func)
obj:DoEvent()
--事件不能直接设置为空

8、二维数组

使用GetValue获取


[LuaCallCSharp]
public class Book : MonoBehaviour
{public int[,] INTArray;void Awake(){INTArray = new int[3, 3]{{1,2,3},{2,4,5},{6,7,8}};}public int GetArrayValue(int x,int y){return INTArray[x, y];}public void SetArrayValue(int x,int y,int value){INTArray[x, y] = value;}
}local book = CS.Book
local go = GameObject("二维数组")local obj = go:AddComponent(typeof(book))-- 调用 GetArrayValue 方法
local c = obj:GetArrayValue(1, 1)
print(c)

9、nil

PrimitiveType=CS.UnityEngine.PrimitiveType
Rigidbody=CS.UnityEngine.Rigidbody
local GameObject = CS.UnityEngine.GameObject;
local obj = GameObject("Cube")
local obj2 = GameObject.CreatePrimitive(PrimitiveType.Cube)
local rig = obj2:GetComponent(typeof(Rigidbody))
-- nil和Null没法进行 == 比较
if rig == nil thenprint("空啊")
end
print("不为空吗")--可用这样
if rig:Equals(nil) thenobj2:AddComponent(typeof(Rigidbody))
end
-- 全局函数
print(IsNull(rig))
-- 在C#中
print(rig:Equ())
-- 判断全局函数
function IsNull(obj)if obj==nil or obj:Equals(nil) thenreturn trueendreturn false
end

10、C# 扩展方法

[LuaCallCSharp]
public static class ObjTest
{public static bool Equ(this Object obj){return obj==null;}
}

11、特殊问题

CSharpCallLua :委托、接口

LuaCallCSharp:拓展方法时、建议每个类都加

无法为系统类或者第三方库代码加上这两个特性

Obj = CS.UnityEngine.GameObject
Ui = CS.UnityEngine.UI
local sid=Obj.Find("Slider")
local sliders=sid:GetComponent(typeof(Ui.Slider))
sliders.onValueChanged:AddListener(function(f)print("你好")
end)---------------------------------------------------------------
public static class Lesson10
{[CSharpCallLua]public static List<Type> cSharpCallLua = new List<Type>(){typeof(UnityAction<float>)};[LuaCallCSharp]public static List<Type> luaCallCSharp=new List<Type>(){typeof(GameObject)};
}
----------------------------------------------------------------
local ani=Obj.Find("Btn")
local btn=ani:GetComponent(typeof(Ui.Button))
btn.onClick:AddListener(function()print("鼠标点击了")
end)---还可以这样
local c=CS.UnityEngine.Events.UnityAction(function()print("鼠标点击了")
end)

12、协程

--xlua提供的一个工具表,一定要通过require调用后才能用
local util=require('xlua.util')
GameObject = CS.UnityEngine.GameObject
WaitForSeconds = CS.UnityEngine.WaitForSeconds
--在场景中创建一个空物体,然后添加一个脚本
local obj = GameObject("Coroutine")
local mono = obj:AddComponent(typeof(CS.LuaCallC))
--希望用来被开启的协程函数
fun = function()local a = 1while true docoroutine.yield(WaitForSeconds(1))print(a)a = a + 1if a>10 then--关闭协程mono:StopCoroutine(b)endend
end
--我们不能直接将lua函数传入到开启协程中
--如果要把lua函数当做协程函数传入
--必须先调用xlua.util 中的cs_generator(fun)
b=mono:StartCoroutine(util.cs_generator(fun))

13、泛型

支持有约束有参数的泛型函数

不支持没有约束的泛型番薯

不支持有约束,但是没有参数的泛型函数

不支持非Class的约束

public class Lesson12
{public class TestFather{}public class TestChild:TestFather{}public void TestFun1<T>(T a,T b) where T:TestFather{Debug.Log("有参数有约束的泛型方法");}public void TestFun2<T>(T a,T b) {Debug.Log("有参数无约束的泛型方法");}public void TestFun3<T>(T a) {Debug.Log("有参数");}public void TestFun3<T>() where T:TestFather{Debug.Log("有参数");}  }
local obj=CS.Lesson12()
local child=CS.Lesson12.TestChild()
local father=CS.Lesson12.TestFather()------------默认情况下支持----------
--支持有约束有参数的泛型函数
obj:TestFun1(child,father)
-----------------------------------注意 如果是mono 这种方式支持使用
--但是如果是iLcpp打包 泛型参数是引用类型才可以--要使得可用用
--设置泛型类型再使用
local testFun2=xlua.get_generic_method(CS.Lesson12,"TestFun3")
local testFun2_R=testFun2(CS.System.Int32)
--调用
testFun2_R(obj,10)--设置泛型类型再使用
local testFun3=xlua.get_generic_method(CS.Lesson12,"TestFun2")
local testFun3_R=testFun3(CS.System.Int32)
--调用
testFun3_R(obj,10,20)

相关文章:

Unity开发游戏使用XLua的基础

Unity使用Xlua的常用编码方式&#xff0c;做一下记录 1、C#调用lua 1、Lua解析器 private LuaEnv env new LuaEnv();//保持它的唯一性void Start(){env.DoString("print(你好lua)");//env.DoString("require(Main)"); 默认在resources文件夹下面//帮助…...

AI-ISP论文Learning to See in the Dark解读

论文地址&#xff1a;Learning to See in the Dark 图1. 利用卷积网络进行极微光成像。黑暗的室内环境。相机处的照度小于0.1勒克斯。索尼α7S II传感器曝光时间为1/30秒。(a) 相机在ISO 8000下拍摄的图像。(b) 相机在ISO 409600下拍摄的图像。该图像存在噪点和色彩偏差。©…...

OpenCV:开运算

目录 1. 简述 2. 用腐蚀和膨胀实现开运算 2.1 代码示例 2.2 运行结果 3. 开运算接口 3.1 参数详解 3.2 代码示例 3.3 运行结果 4. 开运算应用场景 5. 注意事项 6. 总结 相关阅读 OpenCV&#xff1a;图像的腐蚀与膨胀-CSDN博客 OpenCV&#xff1a;闭运算-CSDN博客 …...

38. RTC实验

一、RTC原理详解 1、6U内部自带到了一个RTC外设&#xff0c;确切的说是SRTC。6U和6ULL的RTC内容在SNVS章节。6U的RTC分为LP和HP。LP叫做SRTC&#xff0c;HP是RTC&#xff0c;但是HP的RTC掉电以后数据就丢失了&#xff0c;即使用了纽扣电池也没用。所以必须要使用LP&#xff0c…...

Flutter 新春第一弹,Dart 宏功能推进暂停,后续专注定制数据处理支持

在去年春节&#xff0c;Flutter 官方发布了宏&#xff08;Macros&#xff09;编程的原型支持&#xff0c; 同年的 5 月份在 Google I/O 发布的 Dart 3.4 宣布了宏的实验性支持&#xff0c;但是对于 Dart 内部来说&#xff0c;从启动宏编程实验开始已经过去了几年&#xff0c;但…...

巴菲特价值投资思想的核心原则

巴菲特价值投资思想的核心原则 关键词&#xff1a;安全边际、长期投资、内在价值、管理团队、经济护城河、简单透明 摘要&#xff1a;本文深入探讨了巴菲特价值投资思想的核心原则&#xff0c;包括安全边际、长期投资、企业内在价值、优秀管理团队、经济护城河和简单透明的业务…...

C 或 C++ 中用于表示常量的后缀:1ULL

1ULL 是一个在 C 或 C 中用于表示常量的后缀&#xff0c;它具体指示编译器将这个数值视为特定类型的整数。让我们详细解释一下&#xff1a; 1ULL 的含义 1: 这是最基本的部分&#xff0c;表示数值 1。U: 表示该数值是无符号&#xff08;Unsigned&#xff09;的。这意味着它只…...

vue3中el-input无法获得焦点的问题

文章目录 现象两次nextTick()加setTimeout()解决结论 现象 el-input被外层div包裹了&#xff0c;设置autofocus不起作用&#xff1a; <el-dialog v-model"visible" :title"title" :append-to-bodytrue width"50%"><el-form v-model&q…...

程序诗篇里的灵动笔触:指针绘就数据的梦幻蓝图<3>

大家好啊&#xff0c;我是小象٩(๑ω๑)۶ 我的博客&#xff1a;Xiao Xiangζั͡ޓއއ 很高兴见到大家&#xff0c;希望能够和大家一起交流学习&#xff0c;共同进步。 今天我们来对上一节做一些小补充&#xff0c;了解学习一下assert断言&#xff0c;指针的使用和传址调用…...

(三)QT——信号与槽机制——计数器程序

目录 前言 信号&#xff08;Signal&#xff09;与槽&#xff08;Slot&#xff09;的定义 一、系统自带的信号和槽 二、自定义信号和槽 三、信号和槽的扩展 四、Lambda 表达式 总结 前言 信号与槽机制是 Qt 中的一种重要的通信机制&#xff0c;用于不同对象之间的事件响…...

Qt 5.14.2 学习记录 —— 이십이 QSS

文章目录 1、概念2、基本语法3、给控件应用QSS设置4、选择器1、子控件选择器2、伪类选择器 5、样式属性box model 6、实例7、登录界面 1、概念 参考了CSS&#xff0c;都是对界面的样式进行设置&#xff0c;不过功能不如CSS强大。 可通过QSS设置样式&#xff0c;也可通过C代码…...

Hot100之哈希

1两数之和 题目 思路解析 解法1--两次循环 解法2--哈希表一次循环 代码 解法1--两次循环 class Solution {public int[] twoSum(int[] nums, int target) {int nums1[] new int[2];int length nums.length;for (int i 0; i < length; i) {for (int j i 1; j < …...

油漆面积——蓝桥杯

1.题目描述 X 星球的一批考古机器人正在一片废墟上考古。 该区域的地面坚硬如石、平整如镜。 管理人员为方便&#xff0c;建立了标准的直角坐标系。 每个机器人都各有特长、身怀绝技。它们感兴趣的内容也不相同。 经过各种测量&#xff0c;每个机器人都会报告一个或多个矩…...

深度解析:网站快速收录与服务器性能的关系

本文转自&#xff1a;百万收录网 原文链接&#xff1a;https://www.baiwanshoulu.com/37.html 网站快速收录与服务器性能之间存在着密切的关系。服务器作为网站运行的基础设施&#xff0c;其性能直接影响到搜索引擎对网站的抓取效率和收录速度。以下是对这一关系的深度解析&am…...

925.长按键入

目录 一、题目二、思路三、解法四、收获 一、题目 你的朋友正在使用键盘输入他的名字 name。偶尔&#xff0c;在键入字符 c 时&#xff0c;按键可能会被长按&#xff0c;而字符可能被输入 1 次或多次。 你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字&am…...

JavaScript 中的 var 和 let :关键区别与使用建议

在 JavaScript 开发中&#xff0c;变量声明是基础且重要的部分。 var 和 let 都是用于声明变量的关键字&#xff0c;但它们在作用域、变量提升、重复声明等方面存在显著差异。本文将详细探讨它们的区别&#xff0c;并给出使用建议。 1. 作用域 1.1 var 的作用域 …...

寒假刷题Day19

一、923. 三数之和的多种可能 class Solution { public:int threeSumMulti(vector<int>& arr, int target) {const int MOD 1000000007; // 正确的模数long long ans 0; // 使用 long long 防止溢出std::sort(arr.begin(), arr.end());for (size_t i 0; i < a…...

写好简历的三个关键认知

在当今竞争激烈的就业市场中&#xff0c;一份优秀的简历往往是敲开理想企业大门的第一把钥匙。然而&#xff0c;很多求职者在写简历时往往不得要领&#xff0c;让宝贵的机会从指间溜走。今天&#xff0c;让我们一起探讨如何提升简历写作水平&#xff0c;让你的职业之路走得更顺…...

工具的应用——安装copilot

一、介绍Copilot copilot是一个AI辅助编程的助手&#xff0c;作为需要拥抱AI的程序员可以从此尝试进入&#xff0c;至于好与不好&#xff0c;应当是小马过河&#xff0c;各有各的心得。这里不做评述。重点在安装copilot的过程中遇到了一些问题&#xff0c;然后把它总结下&…...

Koa 基础篇(二)—— 路由与中间件

let app new Koa() router.get(“/”,async ctx > { ctx.body “hello koa router” }) app.use(router.routes()) app.use(router.allowedMethods()) app.listen(3000) 运行项目&#xff0c;在浏览器访问本地3000端口&#xff0c;在页面上就会看到输出的语句。这就…...

帆软 FCA -业务分析师认证学习

帆软 FCA -业务分析师认证学习 认证概述 适合人群 企业中有需求管理、指标梳理、业务逻辑梳理、项目规划等需求的人员&#xff0c;想提升综合数据能力、推进数据应用落地的业务/IT骨干。 具体-FCA-业务分析理论 考试要求&#xff1a; FCA-业务分析理论考试- 费用&#xff1a…...

Miniconda 安装及使用

文章目录 前言1、Miniconda 简介2、Linux 环境说明2.1、安装2.2、配置2.3、常用命令2.4、常见问题及解决方案 前言 在 Python 中&#xff0c;“环境管理”是一个非常重要的概念&#xff0c;它主要是指对 Python 解释器及其相关依赖库进行管理和隔离&#xff0c;以确保开发环境…...

solidity高阶 -- Eth支付

在区块链的世界里&#xff0c;智能合约是实现去中心化应用&#xff08;DApp&#xff09;的核心技术之一。Solidity 是一种专门用于编写以太坊智能合约的编程语言&#xff0c;它可以帮助开发者构建各种功能&#xff0c;包括支付功能。 今天&#xff0c;我们就来探讨如何使用 Sol…...

深入理解Java中的String

前言 在Java中&#xff0c;String类是一个非常重要的内置类&#xff0c;用于处理字符串数据。字符串是不可变的&#xff08;immutable&#xff09;&#xff0c;这意味着一旦创建&#xff0c;字符串的内容不能被修改。作为Java中最为基础和常用的类之一&#xff0c;String类在内…...

洛谷 P1734 最大约数和 C语言

P1734 最大约数和 - 洛谷 | 计算机科学教育新生态 题目描述 选取和不超过 S 的若干个不同的正整数&#xff0c;使得所有数的约数&#xff08;不含它本身&#xff09;之和最大。 输入格式 输入一个正整数 S。 输出格式 输出最大的约数之和。 输入输出样例 输入 #1复制 …...

Golang 执行流程分析

文章目录 1. 编译和运行2. 编译和运行说明 1. 编译和运行 如果是对源码编译后&#xff0c;再执行&#xff0c;Go的执行流程如下图 如果我们是对源码直接 执行 go run 源码&#xff0c;Go的执行流程如下图 两种执行流程的方式区别 如果先编译生成了可执行文件&#xff0c;那么…...

python学opencv|读取图像(五十一)使用修改图像像素点上BGR值实现图像覆盖效果

【1】引言 前序学习了图像的得加方法&#xff0c;包括使用add()函数直接叠加BGR值、使用bitwise()函数对BGR值进行按位计算叠加和使用addWeighted()函数实现图像加权叠加至少三种方法。文章链接包括且不限于&#xff1a; python学opencv|读取图像&#xff08;四十二&#xff…...

Flask数据的增删改查(CRUD)_flask删除数据自动更新

查询年龄小于17的学生信息 Student.query.filter(Student.s_age < 17) students Student.query.filter(Student.s_age.__lt__(17))模糊查询&#xff0c;使用like&#xff0c;查询姓名中第二位为花的学生信息 like ‘_花%’,_代表必须有一个数据&#xff0c;%任何数据 st…...

kamailio-ACC模块介绍【kamailio6.0. X】

Acc 模块 作者 Jiri Kuthan iptel.org jiriiptel.org Bogdan-Andrei Iancu Voice Sistem SRL bogdanvoice-system.ro Ramona-Elena Modroiu rosdev.ro ramonarosdev.ro 编辑 Bogdan-Andrei Iancu Voice Sistem SRL bogdanvoice-system.ro Sven Knoblich 1&1 Internet …...

数据库对象

数据库对象 数据库对象是构成数据库结构的基本单位&#xff0c;它们定义了数据库存储的数据类型、数据的组织方式以及数据之间的关系。在数据库中&#xff0c;对象可以包括表&#xff0c;视图&#xff0c;索引&#xff0c;触发器&#xff0c;存储过程&#xff0c;函数等多种类…...