随笔分类 - LUA
摘要:3.5 – Visibility Rules Lua is a lexically scoped language. The scope of a local variable begins at the first statement after its declaration and lasts
阅读全文
摘要:Does the equivalent to t[k] = v, where t is the value at the given index, v is the value at the top of the stack, and k is the value just below the to
阅读全文
摘要:本文翻译自 LUA官方文档 When a function is called, the list of arguments is adjusted to the length of the list of parameters, unless the function is a vararg fu
阅读全文
摘要:You call lua_pcall with the number of arguments you are passing and the number of results you want. The fourth argument indicates an error-handling fu
阅读全文
摘要:setclLvalue(L, L->top, cl); 这是个宏展开是这样: ((L->top)->value_).gc = obj2gco(cl); //top valud gc 设置为 clsour的 gc (L->top)->tt = ctb(LUA_TLCL) //设置top的值为check
阅读全文
摘要:在这一篇文章中我先来介绍一下lua解析一个脚本文件时要用到的一些关键的数据结构,为将来的一系列代码分析打下一个良好的基础。在整个过程中,比较重要的几个源码文件分别是:llex.h,lparse.h、lobject.h和lopcode.h。 在llex.h中 Token代表了一个词法单元,其中toke
阅读全文
摘要:本文转自:http://www.cnblogs.com/nazhizq/p/6525263.html 在llimits.h文件中定义了指令的类型。其实就是32个字节。 上节说到变量最终会存入proto的数组k中,返回的索引放在expdesc *var->u.s.info。那么这个索引就是用来生成中间
阅读全文
摘要:转自:http://www.cnblogs.com/nazhizq/p/6520072.html 上节说到表达式的解析问题,exprstate函数用于解析普通的赋值表达式。lua语言支持多变量赋值。本文先从单变量赋值表达式讲起。 对于简单的两个数的求和过程,lua源码是如何解析的呢? 首先,当词法分
阅读全文
摘要:本文选自:http://www.cnblogs.com/nazhizq/p/6516561.html 一步步调试,在lparser.c文件中luaY_parser函数是语法分析的重点函数,词法分析也是在这个过程中调用的。在这个过程中,用到一些数据结构,下面会详细说。 好,不着急,一步一步来看。lua
阅读全文
摘要:本文转自:http://www.cnblogs.com/zxh1210603696/p/4458473.html 首先利用lua提供的函数luaL_dofile来执行一个lua脚本。 可以看到有两个过程,首先luaL_loadfile函数将lua文件加载进来然后进行词法语法语义分析,得到一个clos
阅读全文
摘要:local t1= {10,11} function t1.Show() print("t1 show") end function GetT() return t1 end local t2 = GetT() t2[1] = 5 --修改t2会同步修改t1 print(t1[1]) t1[1] = 55 --修改t1会同步修改t2 print(t2[1]) t1 = ni...
阅读全文
摘要:>lua -e "io.stdout:setvbuf 'no'" "main.lua" 12345678910111234567891011>Exit code: 0
阅读全文
摘要:http://bbs.pediy.com/showthread.php?p=1428203#post1428203
阅读全文
摘要:LuaTinker的bug和缺陷 LuaTinker是一套还不错的C++代码和Lua代码的绑定库,作者是韩国人Kwon-il Lee,作者应该是参考了LuaBind后,为了简化和避免过重而实现的。其官网在http://gpgstudy.com/gpgiki/LuaTinker ,但可惜全部是韩文的,
阅读全文
摘要:middleclass使在lua中面象对象变的简单抄了一遍他的示例代码运行着试了试,基本懂了local class = require 'middleclass'--类的继承Person = class('Person') --定义一个Person类function Person:initiali...
阅读全文
摘要:今天在改一个程序,改成部分逻辑用lua写,这个程序是多线程的。将程序中部分逻辑改成lua之后,各种非法访问内存错误,各种奇奇怪怪的问题,不分时间,不分地点的出现崩溃。从调用堆栈来看,基本都是使用lua造成的。在多线程中使用lua_newthread得到的lus_State仍然有时候程序会崩溃。基本上可以确定为多线程中操作lua 的问题了。 前几天我转载的一篇文章,文章写了关于lua多线程的作法。...
阅读全文
摘要:转自http://www.cnblogs.com/ghost240/p/3526185.html最近写paintsnow::start时出现了一个非常麻烦的BUG,程序的Release版本大约每运行十几次就会有一次启动时崩溃(Debug版本还没崩溃过),崩溃点也不固定。经过简单分析之后,确定是线程同...
阅读全文
摘要:本实例实现一种很简单的类型------布尔数组。C语言可以实现将每个布尔值存储在一个bit中,从而减少内存用量。必须的一些宏Code Snippet#defineBITS_PER_WORD (CHAR_BIT * sizeof(unsignedint))//bit#defineI_WORD(i) (...
阅读全文
摘要:1 如何封装c++的指针对于c++对象的lua包装,我们可以使用templatestruct luaUserdataWrapper{luaUserdataWrapper() {}luaUserdataWrapper(const T& d) : data(d) {}T data;};class CObject{public: int v[10];};typedef luaUserdataWrapper luaObject;这样就可以在c代码中,按照如下方法向lua中添加生成CObject的对象的C函数:int NewObject( lua_State* L ){luaObject* wr
阅读全文
摘要:lua代码返回值为真c++lua_toboolean 返回一个 int lua true = 1 false = 0c++给lua返回lua_pushboolean 1 = true 0 = falsec++ 中1为真0为假-1b也为真
阅读全文