vrep:build-lua-module-from-c
Differences
This shows you the differences between two versions of the page.
— | vrep:build-lua-module-from-c [2023/03/31 12:14] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Back to [[vrep: | ||
+ | |||
+ | 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:// | ||
+ | <code bat> | ||
+ | @echo off | ||
+ | :: ======================== | ||
+ | :: file build.cmd | ||
+ | :: ======================== | ||
+ | setlocal | ||
+ | :: you may change the following variable' | ||
+ | :: 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: | ||
+ | set lua_install_dir=c: | ||
+ | set compiler_bin_dir=c: | ||
+ | set lua_build_dir=%work_dir%\lua-%lua_version% | ||
+ | set path=%compiler_bin_dir%; | ||
+ | |||
+ | cd /D %lua_build_dir% | ||
+ | mingw32-make PLAT=mingw | ||
+ | |||
+ | echo. | ||
+ | echo **** COMPILATION TERMINATED **** | ||
+ | echo. | ||
+ | echo **** BUILDING BINARY DISTRIBUTION **** | ||
+ | echo. | ||
+ | |||
+ | :: create a clean " | ||
+ | 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" | ||
+ | |||
+ | 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**, | ||
+ | <code Makefile> | ||
+ | $(LUA_A): $(CORE_O) $(LIB_O) | ||
+ | $(AR) $@ $(CORE_O) $(LIB_O) | ||
+ | $(RANLIB) $@ | ||
+ | </ | ||
+ | can be changed in : | ||
+ | <code Makefile> | ||
+ | # 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 : | ||
+ | <code bash> | ||
+ | C: | ||
+ | … | ||
+ | Hello! | ||
+ | Simple Lua test successful!!! | ||
+ | |||
+ | Press any key to continue . . . | ||
+ | </ | ||
+ | |||
+ | The **path** environment variable can be set to use directly the LUA interpreter : | ||
+ | <code batch> | ||
+ | C: | ||
+ | </ | ||
+ | Then the LUA interpreter can be simply used by typing **lua** in the command line : | ||
+ | <code batch> | ||
+ | C: | ||
+ | Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio | ||
+ | > a=2 | ||
+ | > b=3 | ||
+ | > print (a*b) | ||
+ | 6 | ||
+ | > ^C | ||
+ | C: | ||
+ | </ | ||
+ | To quit, type Ctrl-C. | ||
+ | |||
+ | |||
+ | ==== 2 - Installing " | ||
+ | |||
+ | Many LUA additional modules can be found [[http:// | ||
+ | First we get the source code of [[http:// | ||
+ | | ||
+ | A new **Makefile** is defined as follows : | ||
+ | <code Makefile> | ||
+ | LUA_DIR=c: | ||
+ | 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** : | ||
+ | <code batch> | ||
+ | C: | ||
+ | gcc -Ic: | ||
+ | gcc -o pack.dll -shared | ||
+ | lua test.lua | ||
+ | 1B4C75615100010404040800 | ||
+ | false 12 | ||
+ | 13 27 Lua | ||
+ | A1B0B91212B9B0A1A1B0B912 | ||
+ | 13 314159265 | ||
+ | F1D4C853FB210940400921FB53C8D4F1F1D4C853FB210940 | ||
+ | 25 3.14159265 | ||
+ | </ | ||
+ | |||
+ | The last thing to do is to copy the module in the V-REP folder : | ||
+ | <code batch> | ||
+ | C: | ||
+ | </ | ||
+ | |||
+ | ==== 2 - useful links ==== | ||
+ | |||
+ | Here are some useful links used to add LUA modules to V-REP. | ||
+ | |||
+ | * IDE : [[https:// | ||
+ | * gcc compiler : [[https:// | ||
+ | * decompress tar.gz : [[https:// | ||
+ | * creating a DLL : [[http:// | ||
+ | * installing LUA on Windows : | ||
+ | * command line arguments : | ||
+ | * Alternate gcc compiler (not used) : [[http:// | ||
+ | * simple LUA module : [[https:// | ||
+ | * adding functionalities to LUA : [[http:// | ||