Back to [[vrep:main|V-REP Main Page]] This page describes how, on Windows10, a new LUA module written in C can be added to V-REP. V-REP uses version 5.1 of LUA but do not provide the files for development. So we first need to install our own LUA interpreter and then we show how to build an additional LUA module written in C. ==== 1 - Installing LUA ==== All versions of LUA can be downloaded from . The code is [[https://www.lua.org/ftp/lua-5.1.5.tar.gz|downloaded]] and decompressed, this should give a folder called ** lua-5.1.5**. A batch file **build.cmd** is used to build the LUA interpreter and libraries. It is a modified version of the [[http://lua-users.org/wiki/BuildingLuaInWindowsForNewbies| original build.cmd file]]. @echo off :: ======================== :: file build.cmd :: ======================== setlocal :: you may change the following variable's value :: to suit the downloaded version set lua_version=5.1.5 set work_dir=%~dp0 :: Removes trailing backslash :: to enhance readability in the following steps set work_dir=%work_dir:~0,-1% set lua_install_dir=c:\lua set compiler_bin_dir=c:\TDM-GCC-64\bin set lua_build_dir=%work_dir%\lua-%lua_version% set path=%compiler_bin_dir%;%path% cd /D %lua_build_dir% mingw32-make PLAT=mingw echo. echo **** COMPILATION TERMINATED **** echo. echo **** BUILDING BINARY DISTRIBUTION **** echo. :: create a clean "binary" installation mkdir %lua_install_dir% mkdir %lua_install_dir%\doc mkdir %lua_install_dir%\bin mkdir %lua_install_dir%\lib mkdir %lua_install_dir%\include copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.* copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.* copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.* copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.* copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.* copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.* copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.* ::copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.* copy %lua_build_dir%\src\liblua.a %lua_install_dir%\lib\*.* copy %lua_install_dir%\bin\lua51.dll %lua_install_dir%\lib\liblua51.dll echo. echo **** BINARY DISTRIBUTION BUILT **** echo. %lua_install_dir%\bin\lua.exe -e"print [[Hello!]];print[[Simple Lua test successful!!!]]" echo. pause This code has to be modified depending on where your c compiler is and where you want LUA to be installed. In the file **lua-5.1.5\src\Makefile**, the comment at end of line 51 should be moved to another place, for example : $(LUA_A): $(CORE_O) $(LIB_O) $(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files $(RANLIB) $@ can be changed in : # DLL needs all object files $(LUA_A): $(CORE_O) $(LIB_O) $(AR) $@ $(CORE_O) $(LIB_O) $(RANLIB) $@ At the end of the execution of the build command, the following text should appear : C:\Users\Me>build … Hello! Simple Lua test successful!!! Press any key to continue . . . The **path** environment variable can be set to use directly the LUA interpreter : C:\Users\Me>setx path "%path%;c:\lua\bin" Then the LUA interpreter can be simply used by typing **lua** in the command line : C:\Users\Me>lua Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > a=2 > b=3 > print (a*b) 6 > ^C C:\Users\Me> To quit, type Ctrl-C. ==== 2 - Installing "pack" module ==== Many LUA additional modules can be found [[http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/|here]] First we get the source code of [[http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/5.1/lpack.tar.gz|lpack]] module for LUA 5.1 and decompress it. A new **Makefile** is defined as follows : LUA_DIR=c:\lua LUA_LIBDIR=$(LUA_DIR)\lib LUA_INCDIR=$(LUA_DIR)\include LIBFLAG= -shared RM= del all: test lpack.o: lpack.c gcc -I$(LUA_INCDIR) -c lpack.c pack.dll: lpack.o gcc -o pack.dll $(LIBFLAG) lpack.o -L$(LUA_LIBDIR) -llua51 clean: $(RM) pack.dll lpack.o test: pack.dll test.lua lua test.lua Then, we build and test the **pack** module using this new **Makefile** : C:\Users\Me\pack>mingw32-make PLAT=mingw gcc -Ic:\lua\include -c lpack.c gcc -o pack.dll -shared lpack.o -Lc:\lua\lib -llua51 lua test.lua 1B4C75615100010404040800 12 false 12 13 27 Lua 81 0 1 4 8 4 8 0 A1B0B91212B9B0A1A1B0B912 13 314159265 314159265 314159265 F1D4C853FB210940400921FB53C8D4F1F1D4C853FB210940 25 3.14159265 3.14159265 3.14159265 The last thing to do is to copy the module in the V-REP folder : C:\Users\Me\pack>copy pack.dll "c:\Program Files\V-REP3\V-REP_PRO_EDU\" ==== 2 - useful links ==== Here are some useful links used to add LUA modules to V-REP. * IDE : [[https://downloads.codelite.org/|codelite]] and it's [[https://wiki.codelite.org/pmwiki.php#toc3||wiki]] * gcc compiler : [[https://jmeubank.github.io/tdm-gcc/|TDM-GCC 9.2.0]] * decompress tar.gz : [[https://www.7-zip.org/download.html|7zip]] * creating a DLL : [[http://mingw.org/wiki/sampleDLL|mingw example]] * installing LUA on Windows :[[http://lua-users.org/wiki/BuildingLuaInWindowsForNewbies|lua-users.org wiki]] * command line arguments :[[https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work|parameters explained]] * Alternate gcc compiler (not used) : [[http://mingw-w64.org/doku.php|mingw-w64]] and how to [[https://ascend4.org/Setting_up_a_MinGW-w64_build_environment#MinGW-w64|setup]] * simple LUA module : [[https://github.com/norman/hello-lua|hello world!]] * adding functionalities to LUA : [[http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/|list of modules]]