diff --git a/.appveyor.yml b/.appveyor.yml index eb83c03..a771153 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -11,7 +11,7 @@ branches: - master build_script: -- cmd: appveyor.msvs.bat +- cmd: ci\appveyor.msvs.bat test: off deploy: off diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..cbcd6ff --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,29 @@ +# Use the latest 2.1 version of CircleCI pipeline process engine. +# See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 + +orbs: + win: circleci/windows@2.2.0 + +# Define a job to be invoked later in a workflow. +# See: https://circleci.com/docs/2.0/configuration-reference/#jobs +jobs: + build: + executor: + name: win/default + shell: cmd.exe + steps: + - checkout + - run: + name: build + shell: cmd.exe + command: ci\ci.mingw.bat + + +# Invoke jobs via workflows +# See: https://circleci.com/docs/2.0/configuration-reference/#workflows +workflows: + mingw: + jobs: + - build + diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 4331438..08977ec 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -21,11 +21,11 @@ jobs: lua-all lua-all.tar.gz luajit-2.0 - key: ${{ runner.os }}-cacher-1 + key: ${{ runner.os }}-cacher-2 restore-keys: | - ${{ runner.os }}-cacher-1 + ${{ runner.os }}-cacher-2 - name: Build & Test Linux - run: ./.github/workflows/ci.linux.sh + run: chmod +x ./ci/ci.linux.sh && ./ci/ci.linux.sh shell: bash build_mingw: runs-on: windows-latest @@ -39,10 +39,10 @@ jobs: lua-all lua-all.tar.gz luajit-2.0 - key: ${{ runner.os }}-cacher-1 + key: ${{ runner.os }}-cacher-2 restore-keys: | - ${{ runner.os }}-cacher-1 + ${{ runner.os }}-cacher-2 - name: Build & Test Windows - run: call .github\workflows\ci.mingw.bat + run: ci\ci.mingw.bat shell: cmd diff --git a/.travis.yml b/.travis.yml index 8117bfb..f308f69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,11 +17,11 @@ branches: before_script: - - chmod +x travis.linux.sh - - chmod +x travis.mac.sh - - chmod +x build.linux.sh - - chmod +x build.mac.sh - - chmod +x prereqs.sh + - chmod +x ./ci/travis.linux.sh + - chmod +x ./ci/travis.mac.sh + - chmod +x ./build.linux.sh + - chmod +x ./build.mac.sh + - chmod +x ./prereqs.sh jobs: @@ -29,11 +29,11 @@ jobs: - os: osx include: - stage: build - script: ./travis.linux.sh + script: ./ci/travis.linux.sh os: linux dist: trusty - stage: build - script: ./travis.mac.sh + script: ./ci/travis.mac.sh osx_image: xcode12.2 os: osx diff --git a/Makefile b/Makefile index a1310bb..6ce4a86 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ debug=0 debug_coverage=0 -GCC=gcc +CC=gcc OBJCOPY=objcopy AR=ar MAKE=make @@ -39,7 +39,6 @@ PLATS=Windows MSVS Unix MacOS Linux FE_Windows=.bat FE_MSVS=.msvs.bat -FE_MSVC=.msvs.bat FE_Unix=.sh FE_Linux=.sh FE_MacOS=.sh @@ -50,10 +49,8 @@ PRE_Unix=./ PRE_Linux=./ PRE_MacOS=./ - # No need to modify below none: - $(warning Make is a joke) @echo "Please do 'make PLAT=plat' where `plat` is one of these:" @echo " $(PLATS)" @echo "Use these targets: clean-prereqs prereqs clean-build build" @@ -71,37 +68,26 @@ default: none prereqs: - $(warning Make is a joke) $(PRE_$(PLAT))prereqs$(FE_$(PLAT)) download driver: - $(warning Make is a joke) $(PRE_$(PLAT))build$(FE_$(PLAT)) driver $(LUA_VER) package: - $(warning Make is a joke) $(PRE_$(PLAT))build$(FE_$(PLAT)) package $(LUA_VER) - clean-build: - $(warning Make is a joke) $(PRE_$(PLAT))build$(FE_$(PLAT)) clean clean-prereqs: - $(warning Make is a joke) $(PRE_$(PLAT))prereqs$(FE_$(PLAT)) clean - reset-prereqs: - $(warning Make is a joke) $(PRE_$(PLAT))prereqs$(FE_$(PLAT)) reset +install: + $(PRE_$(PLAT))build$(FE_$(PLAT)) install $(PREFIX) uninstall: - $(warning Make is a joke) - $(error This program deletes by manual removal. Please delete it yourself.) - -install: - $(warning Make is a joke) - $($PRE_$(PLAT))build$(FE_$(PLAT)) install $(PREFIX) + $(PRE_$(PLAT))build$(FE_$(PLAT)) uninstall $(PREFIX) diff --git a/build.linux.sh b/build.linux.sh index a198bfd..b616c87 100755 --- a/build.linux.sh +++ b/build.linux.sh @@ -48,10 +48,11 @@ help_message() { printf """ Usage: - build build lua-x.x.x Builds the driver with a default package + build driver lua-x.x.x Builds the driver with a default package build package lua-x.x.x Creates packages for the driver build clean Cleans the environment of built files - build install {directory} Installs to a pre-created directory + build install {directory} Installs to a directory + build uninstall {directory} Uninstalls an installation build -? /? --help Shows this help message build and package accepts: @@ -69,8 +70,9 @@ Listens to these variables: GCC_VER - stdlib version Default: gnu99 Notes: - After building, you may need to configure LD_LIBRARY_PATH to bin/Release/* to test - + After building, you may need to configure LD_LIBRARY_PATH=. or bin/Release/* to test + Uninstall will delete the directory you give it and the installed libraries + When uninstalling it's helpful to pipe yes in """ exit 0 } @@ -117,22 +119,6 @@ if [[ "${1}" == "clean" ]]; then exit 0 fi - -# - Basic Installer -------------------------------------------------- - - -if [[ "${1}" == "install" ]]; then - [[ -z "${2}" ]] && error "please specify where to install to" $LINENO - [[ -d "${2}" ]] || error "please create the destination folder first" $LINENO - - printf "Installing to directory (${2})...\n" - cp -r -i ${CWD}/bin/Release/* "${2}" - - printf "Done.\n" - exit 0 -fi - - # - Basic GCC Setup -------------------------------------------------- @@ -156,6 +142,56 @@ incdir="${CWD}/include" dirs="-L${srcdir} -L${libdir} -L${dlldir} -I${srcdir} -I${incdir}" +# - Basic Installer -------------------------------------------------- + + +if [[ "${1}" == "install" ]]; then + installdir=${2} + if [[ -z "${2}" ]]; then + installdir=/usr/local/bin/LuaConsole + fi + + printf "Installing to directory (${installdir})...\n" + install -D -T "${root}/luaw" "${installdir}/luaw" + install -D -T "${root}/lua.ico" "${installdir}/lua.ico" + install ${root}/liblua*.* "/usr/local/lib" + install ${root}/liblc* "${installdir}" + install -D ${root}/lang/* -t "${installdir}/lang" + pushd ${root} + echo liblua*.* > "${installdir}/installation.config" + popd + ldconfig + + printf "Done. Don't forget to add '${installdir}' to your PATH.\n" + exit 0 +fi + + +# - Basic Uninstaller -------------------------------------------------- + + +if [[ "${1}" == "uninstall" ]]; then + if [[ -z "${2}" ]]; then + installdir=/usr/local/bin/LuaConsole + else + installdir="${2}" + fi + printf "Deleting installed dependencies\n" + if [[ ! -f "${installdir}/installation.config" ]]; then + error "installation file missing. uninstallation failed" $LINENO + fi + for dep in $(cat "${installdir}/installation.config"); do + rm -i "/usr/local/lib/$dep" + done + printf "Deleting installation directory (${installdir})...\n" + rm -r -i "${installdir}" + ldconfig + + printf "Done.\n" + exit 0 +fi + + # - Basic Cache Checking --------------------------------------------- @@ -182,9 +218,7 @@ build_luajit() { cp lualib.h "${incdir}" cp lauxlib.h "${incdir}" cp luajit.h "${incdir}" - ln libluajit.so libluajit-5.1.so.2 cp libluajit.so "${dlldir}" - cp libluajit-5.1.so.2 "${dlldir}" popd printf "Finished locally building & installing luajit.\n" @@ -349,5 +383,5 @@ if [[ "$1" == "package" ]]; then exit 0 fi -error "This shouldn't be reached!\n" $LINENO +help_message diff --git a/build.mingw.bat b/build.mingw.bat index 8d28524..bbba673 100644 --- a/build.mingw.bat +++ b/build.mingw.bat @@ -80,6 +80,9 @@ setlocal echo Remove %CWD%\lib\*.a del %CWD%\lib\*.a rmdir /S /Q %CWD%\bin + pushd %CWD%\luajit-2.0\src + %MAKE% clean LUAJIT_A=libmingw_luajit.dll.a + popd echo Done. exit /b 0 @@ -110,7 +113,6 @@ setlocal REM - Basic GCC Setup -------------------------------------------------- - REM GCC setup IF [0] EQU [%debug%] ( set attrib=-std=gnu11 -Wall -O2 set root=%CWD%\bin\Release @@ -232,8 +234,7 @@ setlocal REM -------------------------------------------------------------------- - echo This shouldn't be reached! - goto failure + goto help REM -------------------------------------------------------------------- @@ -244,11 +245,10 @@ setlocal echo Locally building luajit %CWD%\luajit-2.0 ... pushd %CWD%\luajit-2.0\src - IF EXIST "mingw_libluajit.dll" ( + IF EXIST "mingw_libluajit.dll.a" ( echo libluajit.dll already cached. ) ELSE ( - %MAKE% -j%NUMBER_OF_PROCESSORS% - move lua51.dll mingw_libluajit.dll + %MAKE% -j%NUMBER_OF_PROCESSORS% TARGET_DLLNAME=libluajit.dll TARGET_DLLDOTANAME=libmingw_luajit.dll.a ) echo Locally installing luajit %CWD% ... @@ -257,7 +257,8 @@ setlocal copy /Y lualib.h %incdir%\lualib.h copy /Y lauxlib.h %incdir%\lauxlib.h copy /Y luajit.h %incdir%\luajit.h - copy /Y mingw_libluajit.dll %dlldir%\libluajit.dll + copy /Y libluajit.dll %dlldir%\libluajit.dll + copy /Y libmingw_luajit.dll.a ..\..\lib\libmingw_luajit.dll.a popd echo Finished locally building / installing luajit. @@ -316,13 +317,13 @@ setlocal setlocal IF [%1] == [luajit] ( set luaverdef=-DLUA_JIT_51 - set luaverout=%dlldir%\libluajit.dll + set luaverout=-lmingw_luajit.dll ) ELSE ( - set luaverout=%dlldir%\lib%1.dll + set luaverout=-l%1 ) echo Compiling luaw driver package %1... - %gcc% %attrib% %dirs% %luaverdef% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL -c %srcdir%\ldata.c %srcdir%\jitsupport.c + %gcc% %attrib% %dirs% -D__USE_MINGW_ANSI_STDIO=1 -DLC_LD_DLL %luaverdef% -c %srcdir%\ldata.c %srcdir%\jitsupport.c echo Linking luaw driver package liblc%1.dll... %GCC% %attrib% %dirs% -shared -o liblc%1.dll ldata.o jitsupport.o %luaverout% @@ -358,7 +359,7 @@ REM Simplex help message :help echo Usage: echo. - echo build build lua-x.x.x Builds the driver with a default package + echo build driver lua-x.x.x Builds the driver with a default package echo build package lua-x.x.x Creates packages for the driver echo build clean Cleans the environment of built files echo build install [directory] Installs to a pre-created directory diff --git a/build.msvs.bat b/build.msvs.bat index 2d48425..233eb01 100644 --- a/build.msvs.bat +++ b/build.msvs.bat @@ -355,7 +355,7 @@ REM Simplex help message :help echo Usage: echo. - echo build build lua-x.x.x Builds the driver with a default package + echo build driver lua-x.x.x Builds the driver with a default package echo build package lua-x.x.x Creates packages for the driver echo build clean Cleans the environment of built files echo build install [directory] Installs to a pre-created directory diff --git a/ci/appveyor.msvs.bat b/ci/appveyor.msvs.bat new file mode 100644 index 0000000..031a3c2 --- /dev/null +++ b/ci/appveyor.msvs.bat @@ -0,0 +1,105 @@ +@REM MIT License +@REM +@REM Copyright (c) 2017-2021 Cody Tilkins +@REM +@REM Permission is hereby granted, free of charge, to any person obtaining a copy +@REM of this software and associated documentation files (the "Software"), to deal +@REM in the Software without restriction, including without limitation the rights +@REM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +@REM copies of the Software, and to permit persons to whom the Software is +@REM furnished to do so, subject to the following conditions: +@REM +@REM The above copyright notice and this permission notice shall be included in all +@REM copies or substantial portions of the Software. +@REM +@REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +@REM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +@REM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +@REM AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +@REM LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +@REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +@REM SOFTWARE. + +@echo off + +setlocal + + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" + + REM Init + echo ^> PREREQS + call prereqs.bat download + + REM Building + echo ^> BUILDING + set debug=1 + call build.msvs.bat driver luajit + call build.msvs.bat package lua-5.4.2 + call build.msvs.bat package lua-5.3.6 + call build.msvs.bat package lua-5.2.4 + call build.msvs.bat package lua-5.1.5 + echo Building complete. + + dir bin\Debug + + + REM Testing + echo ^> TESTING + pushd bin\Debug + echo Test 1 + luaw -e "print('Everything went okay')" + + echo Test 2 + luaw -w luajit -e "print('Everything went okay')" + + echo Test 3 + luaw -w lua-5.3.6 -e "print('Everything went okay')" + + echo Test 4 + luaw -w lua-5.2.4 -e "print('Everything went okay')" + + echo Test 5 + luaw -w lua-5.1.5 -e "print('Everything went okay')" + + echo Test 6 + luaw res\testing.lua -Dtest=5 -n a b c + echo Test 6 end + + echo Test 7 + luaw -b res\testing.lua testing.luac + luaw testing.luac -Dtest=5 -n a b c + echo Test 7 end + + echo Test 8 + luaw -w luajit -c -o testing.luac "res\testing.lua" + luaw -w luajit -ltesting.luac -Dtest=5 -n a b c + echo Test 8 end + + echo Test 9 + luaw -w lua-5.4.2 -c -o testing.luac "res\testing.lua" + luaw -w lua-5.4.2 -ltesting.luac -Dtest=5 -n a b c + echo Test 9 end + + echo Test 10 + luaw -w lua-5.3.6 -c -o testing.luac "res\testing.lua" + luaw -w lua-5.3.6 -ltesting.luac -Dtest=5 -n a b c + echo Test 10 end + + echo Test 11 + luaw -w lua-5.2.4 -c -o testing.luac "res\testing.lua" + luaw -w lua-5.2.4 -ltesting.luac -Dtest=5 -n a b c + echo Test 11 end + + echo Test 12 + luaw -w lua-5.1.5 -c -o testing.luac "res\testing.lua" + luaw -w lua-5.1.5 -ltesting.luac -Dtest=5 -n a b c + echo Test 12 end + + echo Testing complete. + popd + +endlocal + + +exit /b 0 + diff --git a/.github/workflows/ci.linux.sh b/ci/ci.linux.sh old mode 100755 new mode 100644 similarity index 100% rename from .github/workflows/ci.linux.sh rename to ci/ci.linux.sh diff --git a/appveyor.msvs.bat b/ci/ci.mingw.bat similarity index 78% rename from appveyor.msvs.bat rename to ci/ci.mingw.bat index 4ce1d77..6be8783 100644 --- a/appveyor.msvs.bat +++ b/ci/ci.mingw.bat @@ -24,19 +24,9 @@ setlocal - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - - call prereqs.bat download - - call build.msvs.bat driver luajit - - call build.msvs.bat package lua-5.4.2 - - call build.msvs.bat package lua-5.3.6 - - call build.msvs.bat package lua-5.2.4 - - call build.msvs.bat package lua-5.1.5 + ci\github.mingw.bat endlocal + +exit /b 0 diff --git a/.github/workflows/ci.msvs.bat b/ci/ci.msvs.bat similarity index 100% rename from .github/workflows/ci.msvs.bat rename to ci/ci.msvs.bat diff --git a/.github/workflows/ci.mingw.bat b/ci/github.mingw.bat similarity index 91% rename from .github/workflows/ci.mingw.bat rename to ci/github.mingw.bat index cd8092b..68a3058 100644 --- a/.github/workflows/ci.mingw.bat +++ b/ci/github.mingw.bat @@ -26,18 +26,17 @@ setlocal REM Init echo ^> PREREQS - set DLM=curl - call prereqs.bat download + prereqs.bat download REM Building echo ^> BUILDING set debug=1 - call build.mingw.bat driver lua-5.4.2 - call build.mingw.bat package luajit - call build.mingw.bat package lua-5.3.6 - call build.mingw.bat package lua-5.2.4 - call build.mingw.bat package lua-5.1.5 + build.mingw.bat driver luajit + build.mingw.bat package lua-5.4.2 + build.mingw.bat package lua-5.3.6 + build.mingw.bat package lua-5.2.4 + build.mingw.bat package lua-5.1.5 echo Building complete. dir bin\Debug diff --git a/travis.linux.sh b/ci/travis.linux.sh similarity index 100% rename from travis.linux.sh rename to ci/travis.linux.sh diff --git a/travis.mac.sh b/ci/travis.mac.sh similarity index 100% rename from travis.mac.sh rename to ci/travis.mac.sh diff --git a/prereqs.bat b/prereqs.bat index 2f71b75..cd336f3 100644 --- a/prereqs.bat +++ b/prereqs.bat @@ -31,7 +31,7 @@ setlocal IF NOT DEFINED ZIP set "ZIP=7zip" IF NOT DEFINED GIT set "GIT=git" - IF NOT DEFINED DLM set "DLM=bitsadmin" + IF NOT DEFINED DLM set "DLM=curl" REM - Basic Switches --------------------------------------------- @@ -56,7 +56,7 @@ setlocal setlocal EnableDelayedExpansion IF [7zip] == [%ZIP%] ( - where 7z.exe + where 7z IF [!errorlevel!] == [1] ( echo %%ZIP%% - 7zip requested but not found in path goto failure @@ -64,7 +64,7 @@ setlocal ) IF [git] == [%GIT%] ( - where git.exe + where git IF [!errorlevel!] == [1] ( echo %%GIT%% - git requested but not found in path goto failure @@ -72,7 +72,7 @@ setlocal ) IF [bitsadmin] == [%DLM%] ( - where bitsadmin.exe + where bitsadmin IF [!errorlevel!] == [1] ( echo %%DLM%% - bitsadmin requested but not found in path goto failure @@ -80,7 +80,7 @@ setlocal ) IF [curl] == [%DLM%] ( - where curl.exe + where curl IF [!errorlevel!] == [1] ( echo %%DLM%% - curl requested but not found in path goto failure @@ -88,7 +88,7 @@ setlocal ) IF [wget] == [%DLM%] ( - where wget.exe + where wget IF [!errorlevel!] == [1] ( echo %%DLM%% - wget requested but not found in path goto failure @@ -166,8 +166,8 @@ setlocal echo Checking for cached %CWD%\lua-all.tar.gz folder ... IF NOT EXIST "%CWD%\lua-all.tar.gz" ( echo Not found. Downloading... - IF [bitsadmin] == [%DLM%] bitsadmin.exe /TRANSFER "lua-all.tar.gz" "https://www.lua.org/ftp/lua-all.tar.gz" %CWD%\lua-all.tar.gz - IF [wget] == [%DLM%] wget.exe "https://www.lua.org/ftp/lua-all.tar.gz" + IF [bitsadmin] == [%DLM%] bitsadmin /TRANSFER "lua-all.tar.gz" "https://www.lua.org/ftp/lua-all.tar.gz" %CWD%\lua-all.tar.gz + IF [wget] == [%DLM%] wget "https://www.lua.org/ftp/lua-all.tar.gz" IF [curl] == [%DLM%] curl "https://www.lua.org/ftp/lua-all.tar.gz" > %CWD%\lua-all.tar.gz IF NOT EXIST "%CWD%\lua-all.tar.gz" ( echo failed to download lua-all diff --git a/prereqs.sh b/prereqs.sh index a666e79..a086247 100755 --- a/prereqs.sh +++ b/prereqs.sh @@ -26,7 +26,7 @@ # - Basic Variables -------------------------------------------------- -[[ -z "${ZIP}" ]] && ZIP="7zip" +[[ -z "${ZIP}" ]] && ZIP="tar" [[ -z "${GIT}" ]] && GIT="git" [[ -z "${DLM}" ]] && DLM="curl" @@ -164,7 +164,7 @@ if [[ "${1}" == "download" ]]; then if [[ ! -d "${CWD}/lua-all" ]]; then printf "Not found. Unpacking...\n" [[ "${ZIP}" == "tar" ]] && tar xzf "${CWD}/lua-all.tar.gz" - [[ "${ZIP}" == "7zip" ]] && 7z x "${CWD}/lua-all.tar.gz" + [[ "${ZIP}" == "7zip" ]] && 7z x "${CWD}/lua-all.tar.gz" && 7z x "${CWD}/lua-all.tar" [[ -d "${CWD}/lua-all" ]] || error "failed to unpack '${CWD}/lua-all' using ${ZIP}" $LINENO fi printf "Cached.\n" diff --git a/src/luadriver.c b/src/luadriver.c index 680babd..b72d02a 100644 --- a/src/luadriver.c +++ b/src/luadriver.c @@ -41,6 +41,7 @@ #include #include #include +#include #if defined(_WIN32) || defined(_WIN64) # define WIN32_LEAN_AND_MEAN @@ -77,50 +78,107 @@ static inline void check_error(int cond, const char* str) { } } +static inline size_t strip_filename(char* buffer, char delim) +{ + char* iter = buffer; + char* last_slash = 0; + while (*iter++ != 0) + { + if (*iter == delim) + last_slash = iter; + } + iter = last_slash; + while (*iter != 0) + { + *iter = 0; + iter++; + } + return strlen(buffer); +} + int main(int argc, char** argv) { const char* language = 0; + char langbuf[260]; + memset(langbuf, 0, 260); + const char english[] = "/lang/english.txt"; + const char chinese[] = "/lang/chinese.txt"; + const char japanese[] = "/lang/japanese.txt"; + const char russian[] = "/lang/russian.txt"; + const char portuguese[] = "/lang/portuguese.txt"; + const char spanish[] = "/lang/spanish.txt"; #if defined(_WIN32) || defined(_WIN64) - const char english[] = "lang/english.txt"; - const char chinese[] = "lang/chinese.txt"; - const char russian[] = "lang/russian.txt"; - const char portuguese[] = "lang/portuguese.txt"; - const char spanish[] = "lang/spanish.txt"; setlocale(LC_ALL, ""); + DWORD length = GetModuleFileName(NULL, langbuf, 260); + length = strip_filename(langbuf, '\\'); switch(GetUserDefaultUILanguage() | 0xFF) { // first byte is lang id case 0x09: // english - language = "lang/english.txt"; + language = english; break; case 0x04: // chinese - language = "lang/chinese.txt"; + language = chinese; break; case 0x11: // japanese - language = "lang/japanese.txt"; + language = japanese; break; case 0x19: // russian - language = "lang/russian.txt"; + language = russian; break; case 0x16: // portuguese - language = "lang/portuguese.txt"; + language = portuguese; break; case 0x0A: // spanish - language = "lang/spanish.txt"; + language = spanish; break; default: // needs translation >:( - language = "lang/english.txt"; + language = english; break; } #else - language = "lang/english.txt"; + char pathbuf[260]; + memset(pathbuf, 0, 260); + size_t length = readlink("/proc/self/exe", pathbuf, 260); + dirname(pathbuf); + strncpy(langbuf, pathbuf, length); + + char* shortcode = getenv("LANG"); + if (shortcode != NULL) { + uint16_t code = *(uint16_t*) shortcode; + switch (code) + { + case 0x656E: // english + language = english; + break; + case 0x7A68: // chinese + language = chinese; + break; + case 0x6A61: // japanese + language = japanese; + break; + case 0x7275: // russian + language = russian; + break; + case 0x7074: // portuguese + language = portuguese; + break; + case 0x6573: // spanish + language = spanish; + break; + default: // needs translations >:( + language = english; + break; + } + } else { + language = "/lang/english.txt"; + } #endif - - language = "lang/english.txt"; + strcat(langbuf, language); // load language file - lang = langfile_load(language); + lang = langfile_load(langbuf); if(lang == 0) { puts("Failed to load lang file!"); return EXIT_FAILURE; @@ -268,8 +326,12 @@ int main(int argc, char** argv) { luacon_loaddll _luacon_loaddll = (luacon_loaddll) 0; char luastr[260]; - if(ARGS.luaver != 0) { - memset(luastr, 0, 260); + memset(luastr, 0, 260); + strcat(luastr, pathbuf); + strcat(luastr, "/"); + if (ARGS.luaver == 0) { + strcat(luastr, DEFAULT_LUA); + } else { strcat(luastr, "liblc"); strcat(luastr, ARGS.luaver); #if defined(_WIN32) || defined(_WIN64) @@ -281,14 +343,14 @@ int main(int argc, char** argv) { #if defined(_WIN32) || defined(_WIN64) HMODULE luacxt; - luacxt = LoadLibrary(ARGS.luaver == 0 ? DEFAULT_LUA : luastr); + luacxt = LoadLibrary(luastr); check_error(luacxt == 0, _("LC_DLL_MIA")); _luacon_loaddll = (luacon_loaddll) GetProcAddress(luacxt, "luacon_loaddll"); check_error(_luacon_loaddll == 0, _("LC_DLL_NO_FUNC")); #else void* luacxt; - luacxt = dlopen(ARGS.luaver == 0 ? DEFAULT_LUA : luastr, RTLD_NOW); + luacxt = dlopen(luastr, RTLD_NOW); check_error(luacxt == 0, dlerror()); _luacon_loaddll = dlsym(luacxt, "luacon_loaddll");