Lua与C如何实现交互

今天开始看Lua源码,因为项目组用的版本是5.1.4,所以我现在看的也是5.1.4版本的,看懂了以后再看5.2 那些地方有不同就OK了~~ ^_^

先从Lua的栈看起

struct lua_State {
CommonHeader;
lu_byte status;
StkId top; /* first free slot in the stack */
StkId base; /* base of current function */
global_State *l_G;
CallInfo *ci; /* call info for current function */
const Instruction *savedpc; /* `savedpc of current function */
StkId stack_last; /* last free slot in the stack */
StkId stack; /* stack base */
CallInfo *end_ci; /* points after end of ci array*/
CallInfo *base_ci; /* array of CallInfos */
int stacksize;
int size_ci; /* size of array `base_ci */
unsigned short nCcalls; /* number of nested C calls */
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
lu_byte hookmask;
lu_byte allowhook;
int basehookcount;
int hookcount;
lua_Hook hook;
TValue l_gt; /* table of globals */
TValue env; /* temporary place for environments */
GCObject *openupval; /* list of open upvalues in this stack */
GCObject *gclist;
struct lua_longjmp *errorJmp; /* current error recover point */
ptrdiff_t errfunc; /* current error handling function (stack index) */

};

继续阅读

儿童节哈哈

今天是儿童节,我们的游戏也要开启测试了,说实话,心情挺忐忑的。

好久没看过源码了,昨天抽空看了下lua的源码,说实话没看太懂(废话),不过里头很多实现很迷人啊,首先是union的运用。说实话写代码的时候这个关键字根本没用过,也很少见到,但是在lua的源码中用的很多。
继续阅读