【正文】
Lua代碼調(diào)用的新函數(shù)的函數(shù),等等。所有在 lua_前綴。 輔助庫(kù)函數(shù) ( auxlib)提供的函數(shù)。 所有在其中定義的函數(shù)等都以 luaL_打頭(例如,luaL_loadbuffer)。輔助庫(kù)利用 高層次上的抽象;所有 Lua標(biāo)準(zhǔn)庫(kù)都使用了 auxlib?;A(chǔ) API致力于 economy and orthogonality,相反 auxlib致力于實(shí)現(xiàn)一般任務(wù)的實(shí)用性。當(dāng)然,基于你的程序的需要而創(chuàng)建其它的抽象也是非常容易的。需要銘記在心的是, auxlib沒有存取 Lua內(nèi)部的權(quán)限。它完成它所有的工作都是通過正式的基本 API。 頭文件 。 如,調(diào)用 luaopen_io,以創(chuàng)建 io table并注冊(cè) I/O函數(shù)( ,)到 Lua環(huán)境中。 Lua調(diào)用 C DLL include include include include /*定義函數(shù) */ static int MyLuaDLL_HelloWorld(lua_State* L) { MessageBox(NULL,Hello,World,MB_OK)。 return 0。 } static int MyLuaDLL_average(lua_State *L) { /* get number of arguments */ int n = lua_gettop(L)。 double sum = 0。 int i。 /* loop through each argument */ for (i = 1。 i = n。 i++) { /* total the arguments */ sum += lua_tonumber(L, i)。 } /* push the average */ lua_pushnumber(L, sum / n)。 /* push the sum */ lua_pushnumber(L, sum)。 /* return the number of results */ return 2。 } *注冊(cè)函數(shù) */ static const luaL_reg MyLuaDLLFunctions [] = { {HelloWorld,MyLuaDLL_HelloWorld}, {average,MyLuaDLL_average}, {NULL, NULL} }。 int __cdecl __declspec(dllexport) luaopen_MyLuaDLL(lua_State* L) { luaL_openlib(L, MyLuaDLL, MyLuaDLLFunctions, 0)。 return 1。 } local testlib = (,luaopen_MyLuaDLL)。 print (testlib) if(testlib)then testlib()。 else Error end ()。 a,b=(23,33,3344)。 print(average:,a,sum:,b)。