Advertisement
bonustree

How to Manually Install Lua on Windows

Aug 9th, 2013
12,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. VIDEO LINK: http://www.youtube.com/watch?v=X5D_h2X8LCk
  2.  
  3.  
  4. cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c
  5.  
  6. This line compiles all files in the directory with the ".c" extension without linking them (/c) with the fastest possible (/O2) multithreaded (/MD) code
  7.  
  8. NOTICE! IN THE NEXT FEW STEPS X.X MEANS YOUR CURRENT LUA VERSION NUMBER, E.G. 5.2
  9.  
  10.  
  11. link /DLL /IMPLIB:luaX.X.lib /OUT:luaX.X.dll *.obj
  12.  
  13. This will create luaX.X.dll and luaX.X.lib out of all ".obj" files
  14.  
  15. REMEMBER TO RENAME "lua.obj" AND "luac.obj" WITH THE EXTENSION ".o" SO THEY WON'T BE SELECTED!!
  16.  
  17.  
  18. link /OUT:lua.exe lua.o luaX.X.lib
  19.  
  20. This will create lua.exe (interpreter) from lua.o using the luaX.X.lib library
  21.  
  22.  
  23. lib /OUT:luaX.X-static.lib *.obj
  24.  
  25. This will create luaX.X-static.lib from all ".obj" files, similar to step 2, but with no dll and this is using the "lib" command
  26.  
  27.  
  28. link /OUT:luac.exe luac.o luaX.X-static.lib
  29.  
  30. This will create luac.exe (compiler) from luac.o using the luaX.X-static.lib library
  31.  
  32.  
  33.  
  34. This is how I do my directories (parentheses indicate what the folder represents). This also shows notable file locations.
  35.  
  36. /Lua
  37. /X.X
  38. /doc (documentation)
  39. /src (source code)
  40. /lua (lua libraries)
  41. /lib (static libraries we created)
  42. /include (relevant header files)
  43. /lauxlib.h
  44. /lua.h
  45. /lua.hpp
  46. /luaconf.h
  47. /lualib.h
  48. /lua.exe
  49. /luaX.X.dll
  50. /luac.exe
  51.  
  52.  
  53.  
  54. Environment Variables, ? represents a wildcard
  55.  
  56. The lua install directory
  57. LUA_DIR = C:\Program Files\Lua\X.X
  58.  
  59. Where to look for .dll files (C libraries)
  60. LUA_CPATH = ?.dll;%LUA_DIR%\?.dll
  61.  
  62. Where to look for .lua files (Lua libraries)
  63. LUA_PATH = ?.lua;%LUA_DIR%\lua\?.lua
  64.  
  65. Also add the contents of LUA_DIR to PATH
  66.  
  67.  
  68.  
  69. Lua 5.2 test code
  70.  
  71. function is_even(n)
  72. if bit32.band(n,1) == 0 then -- fancy bitwise way to check if a number if even (5.2+ only)
  73. print('Even')
  74. else
  75. print('Odd')
  76. end
  77. end
  78.  
  79.  
  80.  
  81. To setup in Visual Studio 2012
  82.  
  83. go to C/C++ -> General and add $(LUA_DIR)\include to additional include directories.
  84.  
  85. go to Linker -> General and add $(LUA_DIR)\lib to additional library dir
  86.  
  87. go to Linker -> Input and add luaX.X.lib to additional dependencies.
  88.  
  89.  
  90.  
  91. C API test code
  92.  
  93. #include "stdio.h"
  94.  
  95. -- C++ header for the C API
  96. #include "lua.hpp"
  97.  
  98. int main(int argc, char** argv) {
  99. lua_State *L = luaL_newstate();
  100. luaL_openlibs(L); -- open the default Lua libraries
  101.  
  102. if (luaL_dofile(L, "test.lua")) { -- execute the file
  103. const char* err = lua_tostring(L, -1); -- if there was an issue, get the string from the top of the stack...
  104. printf(err); -- ...and print it out
  105. }
  106.  
  107. lua_close(L); -- close the lua state
  108.  
  109. getchar();
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement