【lua学习】6.函数,闭包,错误处理
- 1 數(shù)據(jù)結(jié)構(gòu)和宏
- 1.1 Closure 閉包
- 1.2 Proto 函數(shù)原型
- 1.3 UpVal 外部局部變量(upvalue)
- 1.4 LocVar 局部變量信息
- 1.5 SParser 語法分析所需要的結(jié)構(gòu)
- 1.6 Zio 讀寫流對象
- 1.7 Mbuffer 緩沖對象
- 1.8 lua_Debug 調(diào)試信息
- 1.9 CallInfo 函數(shù)調(diào)用信息
- 1.10 lua_longjmp 跳轉(zhuǎn)信息
- 1.11 虛擬機狀態(tài)碼
- 1.12 luaT_typenames 類型名稱字符串
- 1.13 CallS 調(diào)用函數(shù)結(jié)構(gòu)(f_call的參數(shù))
- 1.14 CCallS 調(diào)用C函數(shù)結(jié)構(gòu) (f_Ccall的參數(shù))
- 2 閉包相關(guān)API
- 2.1 luaF_newproto 新建函數(shù)原型
- 2.2 luaF_newCclosure 新建C閉包
- 2.3 luaF_newLclosure 新建lua閉包
- 2.4 luaF_newupval 新建upvalue(起初為close狀態(tài))
- 2.5 luaF_findupval 尋找open地址為level的upvalue,若找不到則新建一個
- 2.6 luaF_close 關(guān)閉協(xié)程L上所有open地址>=level的upvalue
- 2.7 luaF_freeproto 釋放一個函數(shù)原型
- 2.8 luaF_freeclosure 釋放一個閉包
- 2.9 luaF_freeupval 釋放一個upvalue(若是open狀態(tài),則移出g->uvhead鏈表)
- 2.10 luaF_getlocalname 獲取函數(shù)原型f中的第local_number個存活的局部變量的名字
- 3 函數(shù)調(diào)用相關(guān)API
- 3.1 luaD_protectedparser 保護模式下進行語法分析
- 3.2 luaD_callhook 調(diào)用鉤子方法
- 3.3 luaD_precall 調(diào)用函數(shù)的準備工作
- 3.4 luaD_call 調(diào)用函數(shù)func,期望的返回值時nResults個,第一個返回值在func位置,后面的返回值依次往上
- 3.5 luaD_pcall 以保護模式調(diào)用C函數(shù)func,若有異常則做收尾工作
- 3.6 luaD_reallocCI 重新分配CallInfo數(shù)組并重新設(shè)置ci和end_ci指針的指向
- 3.7 luaD_rawrunprotected 以保護模式執(zhí)行C函數(shù)f,返回狀態(tài)碼
- 3.8 luaD_throw 以錯誤碼errcode拋出異常,若無L->errorJmp,則執(zhí)行g(shù)->panic函數(shù)并退出程序
- 3.9 luaD_seterrorobj 根據(jù)錯誤碼errcode將錯誤信息放在oldtop,棧頂設(shè)為oldtop+1
- 3.10 luaD_poscall 函數(shù)調(diào)用的收尾工作,firstResult為第一個返回值的地址(調(diào)整之前的地址),返回值若為0表示函數(shù)調(diào)用返回值數(shù)量由函數(shù)原型決定
- 3.11 luaD_reallocstack 重新分配棧內(nèi)存
- 3.12 luaD_growstack 給棧擴容(至少擴大2倍)
- 4 錯誤處理API
- 4.1 luaG_errormsg 嘗試調(diào)用錯誤處理函數(shù),參數(shù)是原棧頂?shù)腻e誤信息字符串
- 4.2 luaG_runerror 處理運行時錯誤,為fmt為錯誤信息的格式串
- 4.3 luaG_typeerror 處理類型錯誤
- 4.4 luaG_concaterror 處理字符串連接錯誤
- 4.5 luaG_aritherror 處理算術(shù)錯誤
- 4.6 luaG_ordererror 處理比較錯誤
- 5 對外API
- 5.1 lua_call 調(diào)用L->top-nargs-1處的函數(shù),以其上nargs個值為參數(shù),實際返回值為nresults個
- 5.2 lua_pcall 以保護模式調(diào)用L->top-nargs-1處的函數(shù),以其上nargs個值為參數(shù),實際返回值為nresults個,且錯誤函數(shù)距離棧起始地址偏移為errfunc
- 5.3 lua_cpcall 以保護模式執(zhí)行C函數(shù)func
- 5.4 lua_load 加載函數(shù)
- 5.5 lua_dump 序列化字節(jié)碼
- 5.6 lua_atpanic 設(shè)置兜底異常處理函數(shù)(用于處理未捕獲異常的函數(shù)),返回舊的兜底異常處理函數(shù)
1 數(shù)據(jù)結(jié)構(gòu)和宏
在lua中,函數(shù)是第一類的數(shù)據(jù)類型,也叫閉包。閉包分為Lua閉包和C閉包,Lua閉包中重要的數(shù)據(jù)結(jié)構(gòu)是函數(shù)原型和upvalue地址數(shù)組,而C閉包中重要的數(shù)據(jù)結(jié)構(gòu)是C函數(shù)指針和upvalue數(shù)組。而upvalue數(shù)量為0的閉包,稱為“函數(shù)”。
1.1 Closure 閉包
(lobject.h) Closure 閉包的結(jié)構(gòu)
#define ClosureHeader \CommonHeader; \ //#define CommonHeader GCObject *next; lu_byte tt; lu_byte markedlu_byte isC; \ //是否為C閉包lu_byte nuvalues; \ //upvalue的數(shù)量GCObject* gclist; \ //自己所能關(guān)聯(lián)到的GC對象鏈表,見GC章節(jié)struct Table* env; //環(huán)境表//C閉包的結(jié)構(gòu) typedef struct CClosure {ClosureHeader;lua_CFunction f;//C函數(shù)指針 //typedef int (*lua_CFunction) (lua_State *L);TValue upvalue[1];//第一個upval的首地址 } CClosure;//Lua閉包的結(jié)構(gòu) typedef struct LClosure {ClosureHeader;struct Proto* p;//函數(shù)原型UpVal* upvals[1];//第一個upval地址值所在的首地址 } LClosure;//閉包的結(jié)構(gòu) typedef union Closure {CClosure c;//C閉包LClosure l;//lua閉包 } Closure;1.2 Proto 函數(shù)原型
函數(shù)原型中,重要的結(jié)構(gòu)有:常量數(shù)組,指令數(shù)組,內(nèi)嵌的函數(shù)原型地址的數(shù)組,行號信息數(shù)組,局部變量信息數(shù)組,upvalue名字數(shù)組等等。
(lobject.h) Proto
1.3 UpVal 外部局部變量(upvalue)
(lobject.h) UpVal
typedef struct UpVal {CommonHeader;//#define CommonHeader GCObject *next; lu_byte tt; lu_byte markedTValue* v;//若為open狀態(tài),則指向L->stack中的某個位置,下文我們稱呼為upvalue的open地址;若為close狀態(tài),則指向u.value地址union{TValue value;//upvalue為close狀態(tài)時的值struct//upvalue為open狀態(tài)時的結(jié)構(gòu){struct UpVal *prev;//在g->uvhead鏈表中的前驅(qū)UpValstruct UpVal *next;//在g->uvhead鏈表中的后繼UpVal} l;} u; } UpVal;1.4 LocVar 局部變量信息
(lobject.h) LocVar
typedef struct LocVar {TString* varname;//局部變量名字int startpc;//該局部變量存活的第一個指令序號int endpc;//該局部變量不存活的第一個指令序號 } LocVar;1.5 SParser 語法分析所需要的結(jié)構(gòu)
(ldo.c) SParser
struct SParser {ZIO* z;//讀寫流對象 //typedef struct Zio ZIO;Mbuffer buff;//緩沖對象const char* name;//源代碼名字 }1.6 Zio 讀寫流對象
(lzio.h) Zio
struct Zio {size_t n;//還未讀的字節(jié)數(shù)const char* p;//緩沖區(qū)當前讀到的位置//typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);lua_Reader reader;//讀寫lua代碼塊的函數(shù)void* data;//附加的數(shù)據(jù)lua_State* L;//lua虛擬機 };1.7 Mbuffer 緩沖對象
(lzio.h) Mbuffer
typedef struct Mbuffer {char* buff;//字節(jié)數(shù)組size_t n;//字節(jié)數(shù)size_t buffsize;//字節(jié)數(shù)組的容量 } Mbuffer;1.8 lua_Debug 調(diào)試信息
(lua.h) lua_Debug
struct lua_Debug {int event;const char* name;const char* namewhat;/* `global', `local', `field', `method' */const char* what;/* `Lua', `C', `main', `tail' */const char* source;//源代碼路徑名(短)int currentline;//當前行數(shù)int nups;//upvalues數(shù)量int linedefined;//第一行代碼行數(shù)int lastlinedefined;//最后一行代碼行數(shù)char short_src[LUA_IDSIZE];//源代碼路徑名(短)//#define LUA_IDSIZE 60int i_ci;//當前激活的函數(shù)索引 };1.9 CallInfo 函數(shù)調(diào)用信息
(lstate.h) CallInfo
typedef struct CallInfo {StkId base;//函數(shù)調(diào)用?;?/span>StkId func;//函數(shù)在棧上的位置StkId top;//函數(shù)調(diào)用棧頂位置const Instruction* savedpc;//用于保存指令的執(zhí)行現(xiàn)場,等回到本函數(shù)時再賦值給L->savedpc以恢復現(xiàn)場int nresults;//該函數(shù)期望的返回值數(shù)量int tailcalls;//該函數(shù)尾調(diào)用的層數(shù)(尾調(diào)用不會用新的CallInfo,而是用舊的CallInfo) }1.10 lua_longjmp 跳轉(zhuǎn)信息
(ldo.c) lua_longjmp
struct lua_longjmp {struct lua_longjmp* previous;//跳轉(zhuǎn)信息的前驅(qū)節(jié)點luai_jmpbuf b;//#define luai_jmpbuf jmp_bufvolatile int status;//狀態(tài)碼 }1.11 虛擬機狀態(tài)碼
(lua.h)
#define LUA_YIELD 1 //掛起 #define LUA_ERRRUN 2 //運行時錯誤 #define LUA_ERRSYNTAX 3 //語法錯誤 #define LUA_ERRMEM 4 //內(nèi)存錯誤 #define LUA_ERRERR 5 //在錯誤處理函數(shù)中出錯1.12 luaT_typenames 類型名稱字符串
(ltm.c) 與 lua.h中基礎(chǔ)類型枚舉 和 lobject.h中的擴展類型枚舉一一對應(yīng)
const char *const luaT_typenames[] = {"nil", "boolean", "userdata", "number","string", "table", "function", "userdata", "thread","proto", "upval" };(lua.h) 基礎(chǔ)類型枚舉
#define LUA_TNONE (-1) #define LUA_TNIL 0 #define LUA_TBOOLEAN 1 #define LUA_TLIGHTUSERDATA 2 #define LUA_TNUMBER 3 #define LUA_TSTRING 4 #define LUA_TTABLE 5 #define LUA_TFUNCTION 6 #define LUA_TUSERDATA 7 #define LUA_TTHREAD 8(lobject.h) 擴展類型枚舉
#define LAST_TAG LUA_TTHREAD #define LUA_TPROTO (LAST_TAG+1) #define LUA_TUPVAL (LAST_TAG+2)1.13 CallS 調(diào)用函數(shù)結(jié)構(gòu)(f_call的參數(shù))
(lapi.c) CallS
struct CallS {StkId func;//函數(shù)地址int nresults;//實際返回值個數(shù) };1.14 CCallS 調(diào)用C函數(shù)結(jié)構(gòu) (f_Ccall的參數(shù))
(lapi.c) CCallS
struct CCallS {lua_CFunction func;//C函數(shù) //typedef int (*lua_CFunction) (lua_State *L);void* ud; };2 閉包相關(guān)API
2.1 luaF_newproto 新建函數(shù)原型
(lfunc.c) luaF_newproto 新建函數(shù)原型
Proto* luaF_newproto(lua_State* L) {Proto* f = luaM_new(L, Proto);//#define LAST_TAG LUA_TTHREAD//#define LUA_TPROTO (LAST_TAG+1)luaC_link(L, obj2gco(f), LUA_TPROTO);f->k = NULL;f->sizek = 0;f->p = NULL;f->sizep = 0;f->code = NULL;f->sizecode = 0;f->sizelineinfo = 0;f->sizeupvalues = 0;f->nups = 0;f->upvalues = NULL;f->numparams = 0;f->is_vararg = 0;f->maxstacksize = 0;f->lineinfo = NULL;f->sizelocvars = 0;f->locvars = NULL;f->linedefined = 0;f->lastlinedefined = 0;f->source = NULL;return f; }2.2 luaF_newCclosure 新建C閉包
(lfunc.c) luaF_newCclosure
Closure* luaF_newCclosure(lua_State* L, int nelems, Table* e) {//#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + cast(int, sizeof(TValue)*((n)-1)))Closure* c = cast(Closure*, luaM_malloc(L, sizeCclosure(nelems)));luaC_link(L, obj2gco(c), LUA_TFUNCTION);c->c.isC = 1;c->c.env = e;c->c.nupvalues = cast_byte(nelems);return c; }2.3 luaF_newLclosure 新建lua閉包
(lfunc.c) luaF_newLclosure
Closure* luaF_newLclosure(lua_State* L, int nelems, Table* e) {Closure* c = cast(Closure*, luaM_malloc(L, sizeLclosure(nelems)));luaC_link(L, obj2gco(c), LUA_TFUNCTION);c->l.isC = 0;c->l.env = e;c->l.nupvalues = cast_byte(nelems);while (nelems--){c->l.upvals[nelems] = NULL;} }2.4 luaF_newupval 新建upvalue(起初為close狀態(tài))
(lfunc.c) luaF_newupval
UpVal* luaF_newupval(lua_State* L) {UpVal* uv = luaM_new(L, UpVal);luaC_link(L, obj2gco(uv), LUA_TUPVAL);//#define LUA_TUPVAL (LAST_TAG+2)uv->v = &uv->u.value;//新創(chuàng)建的upvalue的value地址指向u.value地址,表示是close狀態(tài)setnilvalue(uv.v);return uv; }2.5 luaF_findupval 尋找open地址為level的upvalue,若找不到則新建一個
(lfunc.c) luaF_findupval
UpVal* luaF_findupval(lua_State* L, StkId level) {global_State* g = G(L);GCObject** pp = &L->openupval;//open狀態(tài)的upvalue鏈表UpVal* p;//當前遍歷的upvaluewhile (*pp != NULL && (p = ngcotouv(*pp))->v >= level){//找到了v==level的upvalueif (p->v == level){if (isdead(g, obj2gco(p))){changewhite(obj2gco(p));}return p;}pp = &p->next;}//若找不到,則新建一個UpVal* uv = luaM_new(L, UpVal);uv->tt = LUA_TUPVAL;uv->marked = luaC_white(g);uv.v = level;//新的upvalue插入L->openupval鏈表頭部uv->next = *pp;*pp = obj2gco(uv);//新的upvalue插入g->uvhead鏈表頭部uv->u.l.prev = &g->uvhead;uv->u.l.next = g->uvhead.u.l.next;uv->u.l.next->u.l.prev = uv;g->uvhead.u.l.next = uv;return uv; }2.6 luaF_close 關(guān)閉協(xié)程L上所有open地址>=level的upvalue
(lfunc.c) luaF_close
void luaF_close(lua_State* L, StkId level) {UpVal* uv;global_State* g = G(L);//遍歷openupval 鏈表中的upvalue,對于每個upvalue,若其在棧上的地址>=level,將其移出upvalue鏈表//#define ngcotouv(o) check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level){//將該upvalue移出openupval 鏈表GCObject* o = obj2gco(uv);//#define obj2gco(v) (cast(GCObject *, (v)))L->openupval = uv->next;//若該upval已經(jīng)死了,則移出鏈表并釋放掉if (isdead(g, o))//#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS){luaF_freeupval(L, uv);}//若upval沒死,則移出鏈表,設(shè)為close狀態(tài),加入GC管轄范圍else{//upvalue移出鏈表unlinkupval(uv);//將upvalue在棧上指向的值賦值給內(nèi)部的value字段setobj(L, &uv->u.value, uv->v);//將upvalue的v指向自己內(nèi)部的value,即設(shè)為close狀態(tài)uv->v = &uv->u.value;//將upvalue加入gc鏈luaC_linkupval(L, uv);//luaC_linkupval見GC章節(jié)}} }2.7 luaF_freeproto 釋放一個函數(shù)原型
(lfunc.c) luaF_freeproto
void luaF_freeproto(lua_State* L, Proto* f) {//釋放指令數(shù)組luaM_freearray(L, f->code, f->sizecode, Instruction);//釋放子函數(shù)原型數(shù)組luaM_freearray(L, f->p, f->sizep, Proto*);//釋放常量數(shù)組luaM_freearray(L, f->k, f->sizek, TValue);//釋放行號信息數(shù)組luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);//釋放局部變量信息luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);//釋放upvalue名字數(shù)組luaM_freearray(L, f->upvalues, f->sizeupvalues, TString*);//釋放函數(shù)原型本身luaM_free(L, f); }2.8 luaF_freeclosure 釋放一個閉包
(lfunc.c) luaF_freeclosure
void luaF_freeclosure(lua_State* L, Closure* c) {int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : sizeLclosure(c->l.nupvalues);//#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)luaM_freemem(L, c, size); }2.9 luaF_freeupval 釋放一個upvalue(若是open狀態(tài),則移出g->uvhead鏈表)
(lfunc.c) luaF_freeupval
void luaF_freeupval(lua_State* L, UpVal* uv) {//若upvalue的狀態(tài)是open,則將它移出雙鏈表int is_open = uv->v != &uv->u.value;if (is_open){//將uv所在的移出open upval雙鏈表unlinkupval(uv);}//釋放內(nèi)存luaM_free(L, uv); }(lfunc.c) unlinkupval 將uv移出g->uvhead鏈表
static void unlinkupval(UpVal* uv) {uv.u.l.next->u.l.prev = uv->u.l.prev;uv.u.l.prev->u.l.next = uv->u.l.next; }2.10 luaF_getlocalname 獲取函數(shù)原型f中的第local_number個存活的局部變量的名字
(lfunc.c) luaF_getlocalname
const char* luaF_getlocalname(const Proto* f, int local_number, int pc) {for (int i = 0; i < f->sizelocvars && f->locvars[i].startpc <= pc; i++){if (pc < f->locvars[i].endpc)//pc屬于[startpc, endpc)范圍內(nèi),則表示局部變量是存活的{local_number--;if (local_number == 0){return getstr(f->locvars[i].varname);}}}return NULL; }3 函數(shù)調(diào)用相關(guān)API
3.1 luaD_protectedparser 保護模式下進行語法分析
(ldo.c) luaD_protectedparser
int luaD_protectedparser(lua_State* L, ZIO* z, const char* name) {struct SParser p;p.z = z;p.name = name;//#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)luaZ_initbuffer(L, &p.buff);int status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);//#define luaZ_resizebuffer(L, buff, size) (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), (buff)->buffsize = size)//#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)luaZ_freebuffer(L, &p.buff);return status; }(ldo.c) f_parser 通過luaU_undump或luaY_parser生成的函數(shù)原型,最終生成一個閉包,并壓棧
static void f_parser(lua_State* L, void* ud) {struct SParser* p = cast(struct SParser*, ud);//獲取第一個字符int c = luaZ_lookahead(p->z);luaC_checkGC(L);//luaC_checkGC見GC章節(jié)//#define LUA_SIGNATURE "\033Lua"//若第一個字符是 \033 則說明是lua二進制文件,則執(zhí)行l(wèi)uaU_undump;若不是,則說明是lua源文件,則執(zhí)行l(wèi)uaY_parser//luaU_undump見指令章節(jié) luaY_parser見解釋器章節(jié)Proto* tf = ((c == LUA_SIGNATURE[o]) ? luaU_undump : luaY_parser)(L, p->z, &p->buff, p->name);//新建Lua閉包,指定其upvalue數(shù)量為函數(shù)原型的nups,指定其環(huán)境表為Global表,指定其函數(shù)原型Closure* cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L)));cl->l.p = tf;for (int i = 0; i < tf->nups; i++){cl->l.upvals[i] = luaF_newupval(L);}//閉包壓棧setclvalue(L, L->top, cl);incr_top(L);//#define incr_top(L) {luaD_checkstack(L,1); L->top++;} }(lzio.c) luaZ_lookahead 向后讀一個字符,若緩沖對象的內(nèi)容全部讀完了,則繼續(xù)定量讀取文件到緩沖對象中
int luaZ_lookahead(ZIO* z) {//若一個緩沖對象中 未讀的字節(jié)數(shù)為0,也就是全部讀完了,則從文件中繼續(xù)讀取內(nèi)容到緩沖區(qū),若文件也讀完了,則返回EOZif (z->n == 0){//定量讀取文件內(nèi)容,填充到緩沖區(qū),讀到第一個字符if (luaZ_fill(z) == EOZ) //#define EOZ (-1) /* end of stream */{return EOZ;}//由于luaZ_fill多讀了一個字符,且文件指針向后移了一位,所以這里要移回來,未讀的字符數(shù)量也要+1回來z->n++;z->p--;}return char2int(*z->p); }(lzio.c) luaZ_fill 定量讀取文件內(nèi)容到緩沖對象中,返回讀到的第一個字符
int luaZ_fill(ZIO* z) {//定量讀取文件內(nèi)容到緩沖對象中,若文件都讀完了,則返回EOZlua_State* L = z->L;size_t size;const char* buff = z->reader(L, z->data, &size);if (buff == NULL || size == 0){return EOZ;}//返回讀到的第一個字符,也就是說 剩余未讀的有size-1個,緩沖區(qū)指針指向索引為1的字符z->n = size - 1;z->p = buff;return char2int(*(z->p++)); }3.2 luaD_callhook 調(diào)用鉤子方法
(ldo.c) luaD_callhook
//typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); void luaD_callhook(lua_State* L, int event, int line) {lua_Hook hook = L->hook;if (hook && L->allowhook){ptrdiff_t top = savestack(L, L->top);//#define savestack(L,p) ((char *)(p) - (char *)L->stack)ptrdiff_t ci_top = savestack(L, L->ci->top);lua_Debug ar;ar.event = event;ar.currentline = line;if (event == LUA_HOOKTAILRET){ar.i_ci = 0;//尾調(diào)用,沒有調(diào)試信息}else{ar.i_ci = cast_int(L->ci, L->base_ci);}luaD_checkstack(L, LUA_MINSTACK);L->ci->top = L->top + LUA_MINSTACK;L->allowhook = 0;//在鉤子函數(shù)調(diào)用過程中不允許再調(diào)用鉤子//調(diào)用鉤子函數(shù)(*hook)(L, &ar);L->allowhook = 1;L->ci->top = restorestack(L, ci_top);L->top = restorestack(L, top);} }3.3 luaD_precall 調(diào)用函數(shù)的準備工作
(ldo.c) luaD_precall 調(diào)用函數(shù)的準備工作
int luaD_precall(lua_State* L, StkId func, int nresults) {//要檢測的函數(shù)不是函數(shù)類型,則獲取該函數(shù)的 __call 元方法,插入func位置if (!ttisfunction(func)){func = tryfuncTM(L, func);}ptrdiff_t funcr = savestack(L, func);LClosure* cl = &clvalue(func)->l;L->ci->savedpc = L->savedpc;//保留指令執(zhí)行現(xiàn)場//若為lua函數(shù)if (!cl->isC){StkId base;Proto* p = cl->p;luaD_checkstack(L, p->maxstacksize);//luaD_checkstack可能會導致L->stack重新分配內(nèi)存,所以需要配套使用 savestack宏 和 restorestack宏func = restorestack(L, funcr);//若無可變參數(shù)if (!p->is_vararg){base = func + 1;//限制棧頂為 最后一個形參 的 下一個位置if (L->top > base + p->numparams){L->top = base + p->numparams;}}//若有可變參數(shù)else{//實參數(shù)量int nargs = cast_int(L->top - func) - 1;//根據(jù)函數(shù)原型 和 實參數(shù)量 調(diào)整 棧結(jié)構(gòu)base = adjust_varargs(L, p, nargs);//adjust_varargs可能會導致L->stack重新分配內(nèi)存,所以需要配套使用 savestack宏 和 restorestack宏func = restorestack(L, funcr);}//新增一個CallInfo,壓入L->ci棧//#define inc_ci(L) ((L->ci == L->end_ci) ? growCI(L) : ++L->ci)CallInfo* ci = inc_ci(L);ci->func = func;L->base = ci->base = base;//記錄當前函數(shù)調(diào)用的棧基址ci->top = L->base + p->maxstacksize;L->savedpc = p->code;//指令地址指向函數(shù)原型的第一條指令ci->tailcalls = 0;ci->nresults = nresults;for (StkId st = L->top; st < ci->top; st++){setnilvalue(st);}L->top = ci->top;if (L->hookmask & LUA_MASKCALL){L->savedpc++;luaD_callhook(L, LUA_HOOKCALL, -1);L->savedpc--;}return PCRLUA;}//C函數(shù)else{luaD_checkstack(L, LUA_MINSTACK);//#define LUA_MINSTACK 20CallInfo* ci = inc_ci(L)ci->func = restorestack(L, funcr);L->base = ci->base = ci->func + 1;ci->top = L->top + LUA_MINSTACK;ci->nresults = nresults;if (L->hookmask & LUA_MASKCALL){luaD_callhook(L, LUA_HOOKCALL, -1);}//直接調(diào)用C函數(shù)int n = (*curr_func(L)->c.f)(L);//#define curr_func(L) (clvalue(L->ci->func))if (n < 0)//yield{return PCRYIELD;}else{//函數(shù)調(diào)用收尾工作luaD_poscall(L, L->top - n);return PCRC;}} }(ldo.c) tryfuncTM 將func的__call元方法插入func位置
static StkId tryfuncTM(lua_State* L, StkId func) {const TValue* tm = luaT_gettmbyobj(L, func, TM_CALL);ptrdiff_t funcr = savestack(L, func);//若 func 的 __call 元方法依然不是函數(shù)類型,則報錯if (!ttisfunction(tm)){luaG_typeerror(L, func, "call");}//從 L->top - 1 到 func 位置,所有的元素都上移一位for (StkId p = L->top; p > func; p--){setobjs2s(L, p, p - 1);}incr_top(L);//#define incr_top(L) {luaD_checkstack(L,1); L->top++;}func = restorestack(L, funcr);//incr_top可能會導致L->stack重新分配內(nèi)存,所以需要配套使用 savestack宏 和 restorestack宏//func 位置放 _call 元方法 tmsetobj2s(L, func, tm);return func; }(ldo.c) adjust_varargs 對于可變參數(shù)函數(shù),根據(jù)函數(shù)原型p和實際參數(shù)actual來調(diào)整棧
調(diào)整之后的棧結(jié)構(gòu), […,func,nfixargs個nil,nfixargs個參數(shù),arg表,棧頂位置]
3.4 luaD_call 調(diào)用函數(shù)func,期望的返回值時nResults個,第一個返回值在func位置,后面的返回值依次往上
(ldo.c) luaD_call
void luaD_call(lua_State* L, StkId func, int nResults) {if (++L->nCalls >= LUAI_MAXCCALLS){if (L->nCalls == LUAI_MAXCCALLS){luaG_runeeror(L, "C stack overflow");}else if (L->nCcalls >= (LUAI_MAXCCALLS + LUAI_MAXCCALLS >> 3)){luaD_throw(L, LUA_ERRERR);}}//若為lua函數(shù),則執(zhí)行下一條指令(下一條指令已經(jīng)指向函數(shù)原型第一條指令);而C函數(shù)在luaD_precall的里就已經(jīng)執(zhí)行了if (luaD_precall(L, func, nResults) == PCRLUA){luaV_execute(L, 1);//luaV_execute見指令章節(jié)}L->nCcalls--;luaC_checkGC(L); }3.5 luaD_pcall 以保護模式調(diào)用C函數(shù)func,若有異常則做收尾工作
(ldo.c) luaD_pcall
//typedef void (*Pfunc) (lua_State *L, void *ud); int luaD_pcall(lua_State* L, Pfunc func, void* u, ptrdiff_t old_top, ptrdiff_t ef) {unsigned short oldnCcalls = L->nCcalls;ptrdiff_t old_ci = saveci(L, L->ci);//#define saveci(L,p) ((char *)(p) - (char *)L->base_ci)lu_byte old_allowhooks = L->allowhook;ptrdiff_t old_errfunc = L->errfunc;L->errfunc = ef;//以保護模式執(zhí)行funcint status = luaD_rawrunprotected(L, func, u);//狀態(tài)碼不為0表示有異常if (status != 0){StkId oldtop = restorestack(L, old_top);//關(guān)閉所有 open地址>=oldtop 的upvalaueluaF_close(L, oldtop);//根據(jù)狀態(tài)碼status將錯誤信息放在oldtop位置,并以oldtop的下一個位置為棧頂luaD_seterrorobj(L, status, oldtop);L->nCcalls = oldnCcalls;L->ci = restoreci(L, old_ci);L->base = L->ci->base;L->savedpc = L->ci->savedpc;L->allowhook = old_allowhook;//調(diào)整CallInfo數(shù)組restore_stack_limit(L);}L->errfunc = old_errfunc;return status; }(ldo.c) restore_stack_limit 調(diào)整CallInfo數(shù)組(若CallInfo數(shù)組太大了,且正在使用的CallInfo數(shù)量小于限定值,則重新分配CallInfo數(shù)組)
static void restore_stack_limit(lua_State* L) {if (L->size_ci > LUAI_MAXCALLS)//#define LUAI_MAXCALLS 20000{int inuse = cast_int(L->ci - L->base_ci);if (inuse + 1 < LUAI_MAXCALLS){luaD_reallocCI(L, LUAI_MAXCALLS);}} }3.6 luaD_reallocCI 重新分配CallInfo數(shù)組并重新設(shè)置ci和end_ci指針的指向
(ldo.c) luaD_reallocCI
void luaD_reallocCI(lua_State* L, int newsize) {CallInfo* oldci = L->base_ci;luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);L->size_ci = newsize;L->ci += L->base_ci - oldci;L->end_ci = L->base_ci + L->size_ci - 1; }3.7 luaD_rawrunprotected 以保護模式執(zhí)行C函數(shù)f,返回狀態(tài)碼
(ldo.c) luaD_rawrunprotected
int luaD_rawrunprotected(lua_State* L, Pfunc f, void* ud) {struct lua_longjmp lj;lj.status = 0;lj.previous = L->errorJmp;L->errorJmp = &lj;//#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }LUAI_TRY(L, &lj, (*f)(L, ud););//宏展開就是/*//setjmp一開始為0,會進入if//若f執(zhí)行過程中有l(wèi)ongjmp執(zhí)行,則代碼會跳轉(zhuǎn)到此處,那時setjmp的值由longjmp決定,若不為0,則不進入if了if (setjmp((&lj)->b) == 0){(*f)(L, ud);}*/L->errorJmp = lj.previous;return lj.status; }3.8 luaD_throw 以錯誤碼errcode拋出異常,若無L->errorJmp,則執(zhí)行g(shù)->panic函數(shù)并退出程序
(ldo.c) luaD_throw
void luaD_throw(lua_State* L, int errcode) {if (L->errorJmp){L->errorJmp->status = errcode;//#define LUAI_THROW(L,c) longjmp((c)->b, 1)LUAI_THROW(L, L->errorJmp);}else{L->status = cast_byte(errcode);if (G(L)->panic){resetstack(L, errcode);G(L)->panic(L);}exit(EXIT_FAILURE);} }(ldo.c) resetstack
static void resetstack(lua_State* L, int status) {L->ci = L->base_ci;L->base = L->ci->base;luaF_close(L, L->base);//關(guān)閉所有open地址>=level的upvalueluaD_seterrorobj(L, status, L->base);//根據(jù)錯誤碼status將錯誤信息放在L->base,棧頂設(shè)為L->base+1L->nCcalls = L->baseCcalls;L->allowhook = 1;restore_stack_limit(L);//調(diào)整CallInfo數(shù)組L->errfunc = 0;L->errorJmp = NULL; }3.9 luaD_seterrorobj 根據(jù)錯誤碼errcode將錯誤信息放在oldtop,棧頂設(shè)為oldtop+1
(ldo.c) luaD_seterrorobj
void luaD_seterrorobj(lua_State* L, int errcode, StkId oldtop) {switch (errcode){case LUA_ERRMEM:{setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));//#define MEMERRMSG "not enough memory"break;}case LUA_ERRERR:{setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));break;}case LUA_ERRSYNTAX:case LUA_ERRRUN:{setobjs2s(L, oldtop, L->top - 1);//將L->top-1處錯誤信息移到oldtop處break;}}L->top = oldtop + 1; }3.10 luaD_poscall 函數(shù)調(diào)用的收尾工作,firstResult為第一個返回值的地址(調(diào)整之前的地址),返回值若為0表示函數(shù)調(diào)用返回值數(shù)量由函數(shù)原型決定
(ldo.c) luaD_poscall
int luaD_poscall(lua_State* L, StkId firstResult) {if (L->hookmask & LUA_MASKRET){//觸發(fā)函數(shù)返回鉤子回調(diào)firstResult = callrethooks(L, firstResult); }CallInfo* ci = L->ci--;//恢復L->ci,指向上一個函數(shù)調(diào)用StkId res = ci->func;//第一個返回值的位置int wanted = ci->nresults;//函數(shù)原型的返回值數(shù)量L->base = (ci - 1)->base;//恢復函數(shù)環(huán)境棧基址L->savedpc = (ci - 1)->savedpc;//恢復指令指針//糾正返回值的位置for (int i = wanted; i != 0 && firstResult < L->top; i--){setobjs2s(L, res++, firstResult++);}//多出的實際返回值以nil填充while (i-- > 0){setnilvalue(res++);}//棧頂指向原來的函數(shù)地址處(棧又恢復到了該函數(shù)調(diào)用之前)L->top = res;return (wanted - LUA_MULTRET);//若 wanted == LUA_MULTRET 則返回0 }(ldo.c) callrethooks 觸發(fā)函數(shù)返回的鉤子回調(diào)
static StkId callrethooks(lua_State* L, StkId firstResult) {ptrdiff_t fr = savestack(L, firstResult);//觸發(fā)LUA_HOOKRET鉤子回調(diào)luaD_callhook(L, LUA_HOOKRET, -1);//#define ci_func(ci) (clvalue((ci)->func))//#define f_isLua(ci) (!ci_func(ci)->c.isC)if (f_isLua(L->ci)){//若是尾調(diào)用,逐層觸發(fā)LUA_HOOKTAILRET鉤子回調(diào)while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--){luaD_callhook(L, LUA_HOOKTAILRET, -1);}}return restorestack(L, fr); }3.11 luaD_reallocstack 重新分配棧內(nèi)存
(ldo.c) luaD_reallocstack
void luaD_reallocstack(lua_State* L, int newsize) {//記錄舊棧起始地址,方便后續(xù)調(diào)整棧做參考用TValue* oldstack = L->stack;//棧新的容量int realsize = newsize + 1 + EXTRA_SIZE;//#define EXTRA_STACK 5 預留的空間,比如為元方法調(diào)用預留等//重新分配棧空間luaM_reallocvector(L, L->stack, L->stacksize, realsize, TValue);L->stacksize = realsize;L->stack_last = L->stack + newsize;//根據(jù)棧的舊起始地址調(diào)整棧的 棧頂?shù)刂?#xff0c;upvalue的值的地址,函數(shù)調(diào)用信息的棧頂?shù)刂?、基址、函?shù)地址,?;?/span>correctstack(L, oldstack); }(ldo.c) correctstack 對棧進行糾正(棧頂?shù)刂?#xff0c;upvalue的值的地址,函數(shù)調(diào)用信息的棧頂?shù)刂贰⒒贰⒑瘮?shù)地址,棧基址)
static void correctstack(lua_State* L, TValue* oldstack) {int offset = L->stack - oldstack;//更新棧頂位置L->top += offset;//更新各個upvalue中值的地址for (GCObject* up = L->openupval; up != NULL; up = up->gch.next){//#define gco2uv(o) &((o)->uv)gco2uv(up)->v += offset;}//更新各個函數(shù)調(diào)用信息中的 棧頂?shù)刂?#xff0c;基址,函數(shù)地址for (CallInfo* ci = L->base_ci; ci <= L->ci; ci++){ci->top += offset;ci->base += offset;ci->func += offset;}//更新?;?/span>L->base += offset; }3.12 luaD_growstack 給棧擴容(至少擴大2倍)
(ldo.c) luaD_growstack
void luaD_growstack(lua_State* L, int n) {if (n <= L->stacksize){luaD_reallocstack(L, 2 * L->stacksize);}else{luaD_reallocstack(L, L->stacksize + n);} }4 錯誤處理API
4.1 luaG_errormsg 嘗試調(diào)用錯誤處理函數(shù),參數(shù)是原棧頂?shù)腻e誤信息字符串
(ldebug.c) luaG_errormsg
void luaG_errormsg(lua_State* L) {if (L->errfunc != 0){//注意 L->errfunc 記錄的是 錯誤處理函數(shù)距離棧起始地址的 差值;通過 restorestack 宏還原得到錯誤處理函數(shù)在棧上的地址StkId errfunc = restorestack(L, L->errfunc);if (!ttisfunction(errfunc)){luaD_throw(L, LUA_ERRERR);}setobjs2s(L, L->top, L->top - 1);//棧頂?shù)腻e誤信息字符串向上移一位setobjs2s(L, L->top - 1, errfunc);//錯誤函數(shù)插入到此位置incr_top(L);luaD_call(L, L->top - 2, 1);//調(diào)用錯誤處理函數(shù)}luaD_throw(L, LUA_ERRRUN); }4.2 luaG_runerror 處理運行時錯誤,為fmt為錯誤信息的格式串
(ldebug.c) luaG_runerror
void luaG_runerror(lua_State* L, const char* fmt, ...) {va_list argp;va_start(argp, fmt);//將錯誤信息準備到棧頂 //luaO_pushvfstring功能是將格式化字符串壓棧,返回字符串首地址addinfo(L, luaO_pushvfstring(L, fmt, argp));va_end(argp);luaG_errormsg(L); }(ldebug.c) addinfo 以msg為信息添加更完善的信息
static void addinfo(lua_State* L, const char* msg) {CallInfo* ci = L->ci;//若當前函數(shù)調(diào)用時lua函數(shù),則添加 文件名和行號信息if (isLua(ci)){char buff[LUA_IDSIZE];//#define LUA_IDSIZE 60int line = currentline(L, ci);//獲取當前行號/*static Proto *getluaproto (CallInfo *ci) {return (isLua(ci) ? ci_func(ci)->l.p : NULL);}*/luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);} }(ldebug.c) currentline 根據(jù)函數(shù)調(diào)用信息ci獲取當前執(zhí)行到的行號
static int currentline(lua_State* L, CallInfo* ci) {int pc = currentpc(L, ci);//獲取當前指令索引if (pc < 0){return -1;//只有當前激活的lua函數(shù)才能有行號信息}//#define getline(proto,pc) (((proto)->lineinfo) ? (proto)->lineinfo[pc] : 0)return getline(ci_func(ci)->l.p, pc); }(ldebug.c) currentpc 根據(jù)函數(shù)調(diào)用信息ci獲取當前執(zhí)行的指令索引
static int currentpc(lua_State* L, CallInfo* ci) {if (!isLua(ci)){return -1;//不是lua函數(shù)當然沒有指令索引}if (ci == L->ci){ci->savedpc = L->savedpc;}//#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)//因為savedpc指向的是下一條要執(zhí)行的指令,所以減1表示當前正在處理的指令return pcRel(ci->savedpc, ci_func(ci)->l.p); }(lobject.c) luaO_chunkid 根據(jù)源文件路徑source獲取chunkid字符串,輸出到字符串地址out
void luaO_chunkid(char* out, const char* source, size_t bufflen) {//若源文件路徑以 = 開頭,則去掉 =if (*source == '='){strncpy(out, source + 1, bufflen);out[bufflen - 1] = '\0';}else{if (*source == '@'){source++;//跳過'@'bufflen -= sizeof(" '...' ");size_t l = strlen(source);strcpy(out, "");//若源文件路徑太長了,則帶上省略號,取最后的部分if (l > bufflen){source += l - bufflen;strcat(out, "...");}strcat(out, source);}else{//檢索字符串 source 開頭連續(xù)有幾個字符都不含 \n 或 \r //也就是獲取第一行字符個數(shù)size_t len = strcspn(source, "\n\r");bufflen -= sizeof(" [string \"...\"] ");//若第一行字符太多,則限制為bufflen個if (len > bufflen){len = bufflen;}strcpy(out, "[string \"");if (source[len] != '\0'){strncat(out, source, len);strcat(out, "...");}else{strcat(out, source);}strcat(out, "\"]");}} }4.3 luaG_typeerror 處理類型錯誤
(ldebug.c) luaG_typeerror
void luaG_typeerror(lua_State* L, const TValue* o, const char* op) {const char* name = NULL;const char* t = luaT_typenames[ttype(o)];const char* kind = (isinstack(L->ci, o)) ? getobjname(L, L->ci, cast_int(o - L->base), &name) : NULL;if (kind){//#define LUA_QL(x) "'" x "'"//#define LUA_QS LUA_QL("%s")luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", op, kind, name, t);}else{luaG_runerror(L, "attempt to %s a %s value", op, t);} }(ldebug.c) isinstack 判斷值o是否在函數(shù)調(diào)用ci的棧幀內(nèi)
static int isinstack(CallInfo* ci, const TValue* o) {for (StkId p = ci->base; p < ci->top; p++){if (o == p){return 1;}}return 0; }(ldebug.c) getobjname 根據(jù)函數(shù)調(diào)ci,棧起始地址偏移stackpos位置,獲取對象的名字,輸出到name地址處,返回值有 NULL|“l(fā)ocal”|“global”|“field”|“upvalue”|“method”
static const char* getobjname(lua_State* L, CallInfo* ci, int stackpos, const char** name) {if (isLua(ci)){Proto* p = ci_func(ci)->l.p;int pc = currentpc(L, ci);*name = luaF_getlocalname(p, stackpos + 1, pc);if (*name){return "local";}Instruction i = symbexec(p, pc, stackpos);switch (GET_OPCODE(i)){//...//見指令章節(jié)}}return NULL; }4.4 luaG_concaterror 處理字符串連接錯誤
(ldebug.c) luaG_concaterror
void luaG_concaterror(lua_State* L, StkId p1, StkId p2) {if (ttisstring(p1) || ttisnumber(p1)){p1 = p2;}luaG_typeerror(L, p1, "concatenate"); }4.5 luaG_aritherror 處理算術(shù)錯誤
(ldebug.c) luaG_aritherror
void luaG_aritherror(lua_State* L, const TValue* p1, const TValue* p2) {TValue temp;if (luaV_tonumber(p1, &temp) == NULL){p2 = p1;}luaG_typeerror(L, p2, "perform arithmetic on"); }4.6 luaG_ordererror 處理比較錯誤
(ldebug.c) luaG_ordererror
int luaG_ordererror(lua_State* L, const TValue* p1, const TValue* p2) {const char* t1 = luaT_typenames[ttype(p1)];const char* t2 = luaT_typenames[ttype(p2)];/*nil boolean userdata number string table function thread 的2號字符分別是l o e m r b n r糟了! string 和 thread 的2號字符是相等的嗎,所以2號字符不能作為判斷類型相同的依據(jù)和群友討論了,是一個bug,lua 5.4 已經(jīng)改成了 strcmp(t1, t2) == 0 判斷了*/if (t1[2] == t2[2]){luaG_runerror(L, "attempt to compare two %s value", t1);}else{luaG_runerror(L, "attempt to compare %s with %s", t1, t2);}return 0; }5 對外API
5.1 lua_call 調(diào)用L->top-nargs-1處的函數(shù),以其上nargs個值為參數(shù),實際返回值為nresults個
(lua.c) lua_call
LUA_API void lua_call(lua_State* L, int nargs, int nresults) {StkId func = L->top - (nargs + 1);luaD_call(L, func, nresults);//若實際返回值數(shù)量==函數(shù)原型返回值數(shù)量,L->ci->top = max(L->ci->top, L->top)//#define adjustresults(L,nres) { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }adjustresults(L, nresults); }5.2 lua_pcall 以保護模式調(diào)用L->top-nargs-1處的函數(shù),以其上nargs個值為參數(shù),實際返回值為nresults個,且錯誤函數(shù)距離棧起始地址偏移為errfunc
(lua.c) lua_pcall
LUA_API int lua_pcall(lua_State* L, int nargs, int nresults, int errfunc) {ptrdiff_t func;if (errfunc == 0){func = 0;}else{StkId o = index2adr(L, errfunc);func = savestack(L, o);}struct CallS c;c.func = L->top - (nargs + 1);c.nresults = nresults;//以保護模式執(zhí)行 f_call 這個C函數(shù)int status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);#define adjustresults(L,nres) { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }adjustresults(L, nresults);return status; }(lapi.c) f_call 調(diào)用ud數(shù)據(jù)內(nèi)的func所指的函數(shù)
static void f_call(lua_State* L, void* ud) {struct CallS* c = cast(struct CallS*, ud);luaD_call(L, c->func, c->nresults); }5.3 lua_cpcall 以保護模式執(zhí)行C函數(shù)func
(lapi.c) lua_cpcall
LUA_API int lua_cpcall(lua_State* L, lua_CFunction func, void* ud) {struct CCallS c;c.func = func;c.ud = ud;int status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);return status; }5.4 lua_load 加載函數(shù)
(lapi.c) lua_load
LUA_API int lua_load(lua_State* L, lua_Reader reader, void* data, const char* chunkname) {if (!chunkname){chunkname = "?";}ZIO z;luaZ_init(L, &z, reader, data);int status = luaD_protectedparser(L, &z, chunkname);return status; }(lzio.c) luaZ_init 初始化讀寫流對象
void luaZ_init(lua_State* L, ZIO* z, lua_Reader reader, void* data) {z->L = L;z->reader = reader;z->data = data;z->n = 0;z->p = NULL; }5.5 lua_dump 序列化字節(jié)碼
(lapi.c) lua_dump
//typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); LUA_API int lua_dump(lua_State* L, lua_Writer writer, void* data) {int status;TValue* o = L->top - 1;if (isLfunction(o)) //#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC){status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0);//luaU_dump見指令章節(jié)}else{status = 1;}return status; }5.6 lua_atpanic 設(shè)置兜底異常處理函數(shù)(用于處理未捕獲異常的函數(shù)),返回舊的兜底異常處理函數(shù)
(lapi.c) lua_atpanic
//typedef int (*lua_CFunction) (lua_State *L); LUA_API lua_CFunction lua_atpanic(lua_State* L, lua_CFunction panicf) {lua_CFunction old = G(L)->panic;G(L)->panic = panicf;return old; }總結(jié)
以上是生活随笔為你收集整理的【lua学习】6.函数,闭包,错误处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 异地就医备案登记表怎么办理(异地就医备案
- 下一篇: linux查看文件行数命令(linux查