lib1.c 835 B

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