[10]Lua脚本调用C#中的List和Dictionary

调用还是在上文中使用的C#脚本中Student类:

lua脚本:

print("------------访问使用C#脚本中的List和Dictionary-----------")

student.list:Add(2024)
student.list:Add(5)
student.list:Add(18)
local listSize = student.list.Count
print("list长度".. tostring(listSize)) --遍历list
for i = 0,listSize - 1 do
print("--->" .. student.list[i])
end print(student.list) student.dic:Add(1,"北京")
student.dic:Add(2,"上海")
student.dic:Add(3,"广州")
student.dic:Add(4,"深圳")
--遍历dic
--使用迭代器遍历键值对
local iterDic = student.dic:GetEnumerator()
while iterDic:MoveNext() do
local val = iterDic.Current.Value
print("--->" .. iterDic.Current.Key .. "---".. val)
end --单独遍历键
local iterDicKey = student.dic.Keys:GetEnumerator()
while iterDicKey:MoveNext() do
print("键---" .. iterDicKey.Current)
end --遍历值
local iterDicVal = student.dic.Values:GetEnumerator()
while iterDicVal:MoveNext() do
print("值---" .. iterDicVal.Current)
end ----------------------在lua脚本中新增C#中的dic和list
----比较麻烦 需要新添加要增加的数据结构类型
--新增list
local list2 = System.Collections.Generic.List_int()
list2:Add(5)
list2:Add(16)
print("list2[0]" .. list2[0])
print("list2[1]" .. list2[1]) --新增加字典
local dic2 = System.Collections.Generic.Dictionary_int_string()
dic2:Add(521,"我爱你") local iterDic2 = dic2:GetEnumerator()
while iterDic2:MoveNext() do
local key = iterDic2.Current.Key
local val = iterDic2.Current.Value
print("Dic2---" .. key .. "--" .. val)
end

CustomSetting中新增的使用的C#中的数据结构类型,就此可以体会一下lua中的userdata的数据类型!

[11]Lua中调用C#类中的拓展方法

在lua中调用Student类的拓展方法

--调用拓展类中的方法
local Jack = TestScripts.Student("Jack")
--调用拓展方法 . 调用需要传一个自身引用
Jack.SingSunny(self)
--或者 使用 :调用
Jack:SingSunny()

所调用的C#脚本中的类:

 public static class Tools
{
public static void SingSunny(this Student student)
{
Debug.Log("我在唱周董的晴天!");
}
}
public class Student
{
private string _name; public Student(string name)
{
_name = name;
} public void Speak()
{
Debug.Log("my name is " + _name);
}
//+ 新增数组内容
public int[] array = new int[5] { 1, 2, 3, 4, 5 }; public List<int> list = new List<int>() { 6, 7, 8, 9, 10 }; public Dictionary<int, string> dic = new Dictionary<int, string>(); }

CustomSetting中将拓展类Tools和被拓展的类Student相关联:

调用结果打印:

热更学习笔记10~11----lua调用C#中的List和Dictionary、拓展类中的方法的更多相关文章

  1. APUE学习笔记——10.11~10.13 信号集、信号屏蔽字、未决信号

    如有转载,请注明出处:Windeal专栏 首先简述下几个概念的关系: 我们通过信号集建立信号屏蔽字,使得信号发生阻塞,被阻塞的信号即未决信号. 信号集: 信号集:其实就是一系列的信号.用sigset_ ...

  2. lua学习笔记10:lua简单的命令行

    前面反复使用的命令行,好学喜欢命令行: 一 格公式 lua [options][script][args] 两 详细命令 -e 直接命令传递一个lua -l 加载文件 -i 进入交互模式 比例如.端子 ...

  3. 【视频编解码·学习笔记】11. 提取SPS信息程序

    一.准备工作: 回到之前SimpleH264Analyzer程序,找到SPS信息,并对其做解析 调整项目目录结构: 修改Global.h文件中代码,添加新数据类型UINT16,之前编写的工程中,UIN ...

  4. 《C++ Primer Plus》学习笔记10

    <C++ Primer Plus>学习笔记10 <<<<<<<<<<<<<<<<<&l ...

  5. SpringBoot学习笔记(11):使用WebSocket构建交互式Web应用程序

    SpringBoot学习笔记(11):使用WebSocket构建交互式Web应用程序 快速开始 本指南将引导您完成创建“hello world”应用程序的过程,该应用程序在浏览器和服务器之间来回发送消 ...

  6. javaSE学习笔记(11)--- Map

    javaSE学习笔记(11)--- Map 1.Map集合 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等,这种一一对应的关系,就叫做映射.Jav ...

  7. SQL反模式学习笔记10 取整错误

    目标:使用小数取代整数 反模式:使用Float类型 根据IEEE754标识,float类型使用二进制格式编码实数数据. 缺点:(1)舍入的必要性: 并不是所有的十进制中描述的信息都能使用二进制存储,处 ...

  8. Hadoop学习笔记(10) ——搭建源码学习环境

    Hadoop学习笔记(10) ——搭建源码学习环境 上一章中,我们对整个hadoop的目录及源码目录有了一个初步的了解,接下来计划深入学习一下这头神象作品了.但是看代码用什么,难不成gedit?,单步 ...

  9. APUE学习笔记——10.9 信号发送函数kill、 raise、alarm、pause

    转载注明出处:Windeal学习笔记 kil和raise kill()用来向进程或进程组发送信号 raise()用来向自身进程发送信号. #include <signal.h> int k ...

  10. Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6)

    Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6) 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配置DNS ...

随机推荐

  1. 使用labelimg标注数据集

    labelimg安装 在cmd命令行中运行如下命令: pip install labelimg -i https://pypi.tuna.tsinghua.edu.cn/simple 数据准备 新建一 ...

  2. mogdb里xlog相关的几个参数

    openGauss/MogDB 3.0 闪回恢复测试 本文出处:https://www.modb.pro/db/411368 介绍 闪回恢复功能是数据库恢复技术的一环,可以有选择性的撤销一个已提交事务 ...

  3. Mogdb - 安装报错Failed to encrypt the password for databaseError

    Mogdb - 安装报错 Failed to encrypt the password for databaseError 本文出处:https://www.modb.pro/db/418363 版本 ...

  4. 基于 Scriptable 从零开始美化iOS桌面(一)

    今天我为大家带来新的作品,iOS17桌面组件神器(Scriptable)原创脚本,精美作品分享!喜欢的话就点关注吧!更多脚本正在路上... * script : ONE-Progress.js * v ...

  5. 面向切面编程AOP[二](java @EnableAspectJAutoProxy 代码原理)

    前言 @EnableAspectJAutoProxy 是启动aop功能的意思,那么里面是什么呢? 正文 @Target({ElementType.TYPE}) @Retention(Retention ...

  6. Spark SQL 抽样函数 ——TABLESAMPLE 的坑点

    最近需要实现一段 Spark SQL 逻辑,对数据集进行抽样指定的行数. 由于数据集较大,刚开始的逻辑是,取窗口函数随机排序后 row_number 的前 n 行.但运行速度较慢,所以想起了 TABL ...

  7. 深入解读 Flink SQL 1.13

    简介: Apache Flink 社区 5 月 22 日北京站 Meetup 分享内容整理,深入解读 Flink SQL 1.13 中 5 个 FLIP 的实用更新和重要改进. 本文由社区志愿者陈政羽 ...

  8. [GPT] 有哪些人工智能辅助工具?

      开发人工智能辅助工具可以帮助人们更高效地完成各种任务,并提高生产力和创造力.这些工具可以基于机器学习.深度学习等技术,通过对大量数据进行分析和学习,提供自动化的解决方案. 例如,一个文本翻译工具可 ...

  9. [Go] 注意 go build -o <output> 选项的准确含义

    -o <output> 选项强制执行把构建的可执行文件写入到目标文件或者目标目录中. 如果 output 是已存在的目录,那么所有构建好的文件都将写入到该目录中. 注意:如果目录不存在的话 ...

  10. [FAQ] Member "address" not found or not visible after argument-dependent lookup in address payable.

    顾名思义,address 属性不存在,请检查调用方. 比如:msg.sender.address 会有此提示,在 Solidity Contract 中,msg.sender.balance 是存在的 ...