lib1.c (835B)
1 #include "lua.h" 2 #include "lauxlib.h" 3 4 static int id (lua_State *L) { 5 return lua_gettop(L); 6 } 7 8 9 static const struct luaL_Reg funcs[] = { 10 {"id", id}, 11 {NULL, NULL} 12 }; 13 14 15 /* function used by lib11.c */ 16 LUAMOD_API int lib1_export (lua_State *L) { 17 lua_pushstring(L, "exported"); 18 return 1; 19 } 20 21 22 LUAMOD_API int onefunction (lua_State *L) { 23 luaL_checkversion(L); 24 lua_settop(L, 2); 25 lua_pushvalue(L, 1); 26 return 2; 27 } 28 29 30 LUAMOD_API int anotherfunc (lua_State *L) { 31 luaL_checkversion(L); 32 lua_pushfstring(L, "%d%%%d\n", (int)lua_tointeger(L, 1), 33 (int)lua_tointeger(L, 2)); 34 return 1; 35 } 36 37 38 LUAMOD_API int luaopen_lib1_sub (lua_State *L) { 39 lua_setglobal(L, "y"); /* 2nd arg: extra value (file name) */ 40 lua_setglobal(L, "x"); /* 1st arg: module name */ 41 luaL_newlib(L, funcs); 42 return 1; 43 } 44