lualib.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. (*
  2. ** $Id: lualib.pas,v 1.5 2007-01-20 16:40:27 jfgoulet Exp $
  3. ** Lua standard libraries
  4. ** See Copyright Notice in lua.h
  5. *)
  6. unit lualib;
  7. {$IFNDEF lualib_h}
  8. {$DEFINE lualib_h}
  9. {$ENDIF}
  10. interface
  11. uses
  12. lua;
  13. const
  14. LUA_PACKLIBNAME = 'package';
  15. LUA_COLIBNAME = 'coroutine';
  16. LUA_TABLIBNAME = 'table';
  17. LUA_IOLIBNAME = 'io';
  18. LUA_OSLIBNAME = 'os';
  19. LUA_STRLIBNAME = 'string';
  20. LUA_MATHLIBNAME = 'math';
  21. LUA_DBLIBNAME = 'debug';
  22. function luaopen_base(L: Plua_State): Integer;
  23. cdecl external 'lua5.1.dll';
  24. function luaopen_package(L: Plua_State): Integer;
  25. cdecl external 'lua5.1.dll';
  26. function luaopen_table(L: Plua_State): Integer;
  27. cdecl external 'lua5.1.dll';
  28. function luaopen_io(L: Plua_State): Integer;
  29. cdecl external 'lua5.1.dll';
  30. function luaopen_string(L: Plua_State): Integer;
  31. cdecl external 'lua5.1.dll';
  32. function luaopen_math(L: Plua_State): Integer;
  33. cdecl external 'lua5.1.dll';
  34. function luaopen_debug(L: Plua_State): Integer;
  35. cdecl external 'lua5.1.dll';
  36. (* to help testing the libraries *)
  37. {$IFNDEF lua_assert}
  38. //#define lua_assert(c) (* empty *)
  39. {$ENDIF}
  40. (* compatibility code *)
  41. function lua_baselibopen(L: Plua_State): Integer;
  42. function lua_packlibopen(L: Plua_State): Integer;
  43. function lua_tablibopen(L: Plua_State): Integer;
  44. function lua_iolibopen(L: Plua_State): Integer;
  45. function lua_strlibopen(L: Plua_State): Integer;
  46. function lua_mathlibopen(L: Plua_State): Integer;
  47. function lua_dblibopen(L: Plua_State): Integer;
  48. implementation
  49. function lua_baselibopen(L: Plua_State): Integer;
  50. begin
  51. lua_pushcfunction(L, luaopen_base);
  52. lua_pushstring(L, '');
  53. lua_call(L, 1, 0);
  54. Result := 1;
  55. end;
  56. function lua_packlibopen(L: Plua_State): Integer;
  57. begin
  58. lua_pushcfunction(L, luaopen_package);
  59. lua_pushstring(L, 'package');
  60. lua_call(L, 1, 0);
  61. Result := 1;
  62. end;
  63. function lua_tablibopen(L: Plua_State): Integer;
  64. begin
  65. lua_pushcfunction(L, luaopen_table);
  66. lua_pushstring(L, 'table');
  67. lua_call(L, 1, 0);
  68. Result := 1;
  69. end;
  70. function lua_iolibopen(L: Plua_State): Integer;
  71. begin
  72. lua_pushcfunction(L, luaopen_io);
  73. lua_pushstring(L, 'io');
  74. lua_call(L, 1, 0);
  75. {lua_pushcfunction(L, luaopen_os);
  76. lua_pushstring(L, 'os');
  77. lua_call(L, 1, 0);
  78. Result := 1;}
  79. end;
  80. function lua_strlibopen(L: Plua_State): Integer;
  81. begin
  82. lua_pushcfunction(L, luaopen_string);
  83. lua_pushstring(L, 'string');
  84. lua_call(L, 1, 0);
  85. Result := 1;
  86. end;
  87. function lua_mathlibopen(L: Plua_State): Integer;
  88. begin
  89. lua_pushcfunction(L, luaopen_math);
  90. lua_pushstring(L, 'math');
  91. lua_call(L, 1, 0);
  92. Result := 1;
  93. end;
  94. function lua_dblibopen(L: Plua_State): Integer;
  95. begin
  96. lua_pushcfunction(L, luaopen_debug);
  97. lua_pushstring(L, 'debug');
  98. lua_call(L, 1, 0);
  99. Result := 1;
  100. end;
  101. end.