使用 Lua 编写可嵌入式脚本

Lua环境搭建+Lua基本语法 前期准备:搜索并下载安装LuaForWindows,例:安装完成后开启cmd窗口,输入lua出现版本号证明成功下载安装。 阅读详情

http://www.hackhome.com/InfoView/Article_80376_7.html

使用 Lua 编写可嵌入式脚本

日期:2007年6月2日 作者: 查看:[ 大字体 中字体 小字体]

  • 添加到QQ书签收藏 添加到雅虎收藏 添加到百度收藏 添加到Google书签 添加到Yahoo书签 添加到新浪ViVi 添加到搜狐网摘 添加到365Key网摘 添加到天极网摘 添加到diglog 添加到和讯网摘 添加到POCO网摘 添加到YouNote网摘 添加到博拉网 添加到天下图摘 Del.icio.us digg reddit spurl BlinkList blogmarks
  • <script style="display: none;" type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>     或者像在其他解释性语言中一样,我们可以在代码顶部添加一行 “标识符”(#!),使这个脚本变成可执行的,然后像单独命令一样来运行这个文件:
    $ (echo '#! /usr/bin/lua'; cat factorial.lua) > factorial 
    $ chmod u+x factorial
    $ ./factorial
    enter a number:
    4
    24
                      

     

    Lua 语言

        Lua 具有现代脚本语言中的很多便利:作用域,控制结构,迭代器,以及一组用来处理字符串、产生及收集数据和执行数学计算操作的标准库。在 Lua 5.0 Reference Manual 中有对 Lua 语言的完整介绍(请参见 参考资料)。

        在 Lua 中,只有值 具有类型,而变量的类型是动态决定的。Lua 中的基本类型(值)有 8 种: nil,布尔型,数字,字符串,函数,线程,表 以及 用户数据。前 6 种类型基本上是自描述的(例外情况请参见上面的 Lua 特性 一节);最后两个需要一点解释。

    Lua 表

        在 Lua 中,表是用来保存所有数据的结构。实际上,表是 Lua 中惟一的 数据结构。我们可以将表作为数组、字典(也称为散列 或联合数组)、树、记录,等等。

        与其他编程语言不同,Lua 表的概念不需要是异构的:表可以包含任何类型的组合,也可以包含类数组元素和类字典元素的混合体。另外,任何 Lua 值 —— 包括函数或其他表 —— 都可以用作字典元素的键值。

    要对表进行浏览,请启动 Lua 解释器,并输入清单 1 中的黑体显示的代码。


    清单 1. 体验 Lua 表
    $ lua
    > -- create an empty table and add some elements
    > t1 = {}
    > t1[1] = "moustache"
    > t1[2] = 3
    > t1["brothers"] = true
    > -- more commonly, create the table and define elements
    > all at once
    > t2 = {[1] = "groucho", [3] = "chico", [5] = "harpo"}
    > t3 = {[t1[1]] = t2[1], accent = t2[3], horn = t2[5]}
    > t4 = {}
    > t4[t3] = "the marx brothers"
    > t5 = {characters = t2, marks = t3}
    > t6 = {["a night at the opera"] = "classic"}
    > -- make a reference and a string
    > i = t3
    > s = "a night at the opera"
    > -- indices can be any Lua value
    > print(t1[1], t4[t3], t6[s])
    moustache   the marx brothers classic
    > -- the phrase table.string is the same as table["string"]
    > print(t3.horn, t3["horn"])
    harpo   harpo
    > -- indices can also be "multi-dimensional"
    > print (t5["marks"]["horn"], t5.marks.horn)
    harpo   harpo
    > -- i points to the same table as t3
    > = t4[i]
    the marx brothers
    > -- non-existent indices return nil values
    > print(t1[2], t2[2], t5.films)
    nil     nil     nil
    >  -- even a function can be a key 
    > t = {}
    > function t.add(i,j)
    >> return(i+j)
    >> end
    > print(t.add(1,2))
    3
    > print(t['add'](1,2))
    3
    >  -- and another variation of a function as a key 
    > t = {}
    > function v(x)
    >> print(x)
    >> end
    > t[v] = "The Big Store"
    > for key,value in t do key(value) end
    The Big Store
                      

  • 上一页 [1] [2] [3] [4] [5] [6] [7] 下一页 
============================================
  值得关注的Lua语言 收藏

新一篇: C-Runtime library的string trim函数(学无止境:C函数参考手册需要补课,汗!) | 旧一篇: 线程并发,用标志位同步时要小心

值得关注的Lua语言

札记:
1.Lua流行的速度很快,缘于WOW的缘故吧。
2.参考了一下WOW的脚本,感觉多语言、pet动作的定义可以由lua来完成,这可能是一个好的idea,先看看是否能够通过移植这一关吧
3.这个学习lua的系列不错,写得比较深入,如果有心人看到的话,推荐一下: http://blog.csdn.net/kun1234567/
4.从 http://www.WOWF1.com (大脚, Big foot)这个网址,可以下载WOW的插件,解压后,其中有一些.lua文件,这是最好的lua的例子

注:
前面随便贴了篇DW上的文章留意要关注的东东,被网友看到,以致被误会忽悠,甚歉!(俺可不是本山 :-))

发表于 @ 2007年11月01日 18:48:00|评论(2)|编辑

新一篇: C-Runtime library的string trim函数(学无止境:C函数参考手册需要补课,汗!) | 旧一篇: 线程并发,用标志位同步时要小心


http://blog.csdn.net/hylaking/archive/2007/11/01/1861745.aspx



用ARStudio给众为兴机械臂写Lua脚本:一个嵌入式工程师的跨界开发实录 本文记录了一位嵌入式工程师使用ARStudio为众为兴SCARA机械臂编写Lua脚本的实战经验。文章详细介绍了从嵌入式开发到工业机械臂编程的思维转换、ARStudio环境配置、控制逻辑重构、ModbusTCP通讯优化以及多级安全防护体系的构建,为跨界开发者提供了宝贵的技术参考。 阅读详情

相关推荐

Redis中使用Lua的原理讲解和实战

一、Redis使用Lua的优势 减少网络开销: 不使用 Lua 的代码需要向 Redis 发送多次请求, 而脚本只需一次即可, 减少网络传输; 原子操作: Redis 将整个脚本作为一个原子执行, 无需担心并发, 也就无需事务; 复用: 脚本会永久保存 Redis 中, 其他客户端可继续使用. 二、Lua是什么 Lua is a powerful and fast programming...

FeelTouch Labs 1649

Lua教程(1): C++嵌入Lua脚本

读后感悟:先讲了环境了配置,然后着重讲了c++中如何调用lua,适合入门。如果想学习语法,可以看《lua程序设计》,虽然讲的是lua5.1,但是很多语法还是可以学的。当你学会了最基本的c++与lua调用之后,就可以马上学一些交互代码了,而不是只是看书,那么看了之后,你会很容易忘记的,之前我就是学习lua的时候就是很少敲代码的,所以现在都忘了很多了,程序员还是多写写代码。   原文地址:htt

cbbbc 5577

Image Sensor常见分辨率下HTS,VTS设置

image sensor,HTS,VTS

propor的专栏 4995

lua编写mysql脚本_使用 Lua 编写可嵌入式脚本

2006年6月12日虽然编译性编程语言和脚本语言各自具有自己独特的优点,但是如果我们使用这两种类型的语言来编写大型的应用程序会是什么样子呢?Lua是一种嵌入式脚本语言,它非常小,速度很快,功能却非常强大。在创建其他配置文件或资源格式(以及与之对应的解析器)之前,请尝试一下Lua。尽管诸如Perl、Python、PHP和Ruby之类的解释性编程语言日益被Web应用程序广泛地采纳——它们已经长期用来实...

weixin_42099987的博客 434

ADS1299EEG-FE评估板PCB与BOM深度解析:高精度生物电信号采集硬件设计实战

在模拟电路与混合信号系统设计中,PCB布局和物料选型是决定系统性能上限的关键环节,尤其在高精度数据采集领域。其核心原理在于通过精心的电源分配、信号链规划和接地策略,将芯片数据手册的理论指标转化为板载的实际性能,这直接关系到系统的信噪比与测量精度。对于EEG/ECG这类微伏级生物电信号采集,任何布局不当或物料参数不匹配都可能导致噪声淹没有用信号。因此,深入剖析一个经过验证的参考设计——例如围绕TI ADS1299芯片构建的评估板——具有极高的工程价值。它能具体展示如何在高性能ADC应用中,通过四层板层叠设计、

weixin_29164497的博客 305

minist手写数字的识别代码复现(pytorch 版本)

电脑系统:Windows 10语言环境:Python 3.8.18编译器:jupyter notebook深度学习环境:torch == 1.13.1+cu116显卡及显存: Tesla V100-PCIE-32GB卷积神经网络(Convolutional Neural Network,CNN或ConvNet)是一种 具有局部连接、权重共享等特性的深层前馈神经网络. 目前的卷积神经网络一般是由卷积层、汇聚层和全连接层交叉堆叠而成的 前馈神经网络。

2202_75521293的博客 2628

使用 Lua 编写可嵌入式脚本收藏

http://blog.csdn.net/winark/archive/2007/06/18/1656875.aspx 使用 Lua 编写可嵌入式脚本收藏 新一篇: 分形与分形艺术 | 旧一篇: GLUT 教程 function StorePage(){d=document;t=d.selection?(d.selection.type!=None?d.selectio

skyremember的专栏 1312

应急响应之windows日志分析工具logparser使用

windows日志分析工具logparser使用介绍

u013930899的博客 8133

【转贴】使用 Lua 编写可嵌入式脚本

使用 Lua 编写可嵌入式脚本 Lua 提供了高级抽象,却又没失去与硬件的关联 将此页作为电子邮件发送 ...

weixin_33953249的博客 123

【四旋翼】pixhawk2.4.8-地面站配置-APM固件-四旋翼从装机到试飞

因为MP版本和APM版本的适配问题,真的真的是很大一个坑。最好先走别人走过的路,走通了再去自由发挥,不然白白浪费时间。下面提供我试飞成功过的版本。下面提供任意版本固件和地面站的下载方法。

xifan的博客 3万+

Nvidia Jetson AGX Orin 如何进入 Recovery Mode(刷机注意事项)

Jetson Orin 如何进入Recovery mode + 刷机注意事项

Pandako's Blog 1万+

使用Lua编写可嵌入式脚本

http://www.voosay.com/detail/226963 使用lua编写可嵌入式脚本 lua提供了高级抽象,却又没失去与硬件的关联将此页作为电子邮件发送); //--&gt 未显示需要javascript...

congchenjin2969的博客 387

PT:pt write_change to innovus 脚本

我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1543

用Lua编写iOS程序

用Lua编写iOS程序

qq_43685389的博客 1236

爬虫法律风险与合规边界

爬虫技术的法律边界正在快速收紧。从2017年上海晟品案开启爬虫入刑先河,到2025年Cloudflare区块链溯源技术将违规行为与企业主体永久绑定,合规已从"可选项"变为"必选项"。技术团队需要建立三层防御体系法律合规层:法律适用判定、授权管理、合同审查、隐私政策;技术控制层:访问控制、数据加密、匿名化、审计日志、监控告警;组织管理层:DPO任命、培训体系、应急响应、合规审计、绩效考核。

从事移动开发八年,csdn博客专家,阿里云特邀专家,华为云云享专家,高级网络信息安全工程师,大数据工程师(高级),python技术开发(高级),HarmonyOS 应用开发者高级认证,现在某学校任教。 1169

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

lua

    Lua 是一个小巧的脚本语言。作者是巴西人。该语言的设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能。它的主页是 www.lua.org。   Lua脚本可以很容易的被C/C++代码调用,也可以反过来调用C/C++的函数,这使得Lua在应用程序中可以被广泛应用。不仅仅作为扩展脚本,也可以作为普通的配置文件,代替XML,Ini等文件格式,并且更容易理解

leelong80的专栏 551

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

lua延时函数c语言,C语言拓展实现Lua sleep函数

这几天在做一个小项目,其中用到了一些基本的API,例如sleep,获取当前目录等等,lua标准库中没有提供这些接口,虽然所第三方库中也都有实现,但是要用的就那么几个函数,在一个嵌入式系统中安装那么多第三方库有点浪费资源,于是@胜利哥 写了一个socket的C实现,然后给我用。我试着把其他几个函数也用C实现,首先看下怎么用C写lua的拓展。C 部分首先是根据Lua C语言的协议写好调用模块,编译成....

weixin_36392230的博客 741

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

上一篇: 你用哪一套script 語言呢
下一篇: 由于应用程序配置不正确,程序未能启动”--原因及解决方法
skyremember
博客等级 码龄20年 205粉丝 484原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址