yuin / gopher-lua

GopherLua: VM and compiler for Lua in Go
MIT License
6.24k stars 649 forks source link

"no field package.preload['http']" on android #300

Closed axengine closed 4 years ago

axengine commented 4 years ago
  1. What version of GopherLua are you using? : github.com/yuin/gopher-lua v0.0.0-20200603152657-dc2b0ca8b37e github.com/cjoudrey/gluahttp v0.0.0-20190104103309-101c19a37344
  2. What version of Go are you using? : go1.13.12
  3. What operating system and processor architecture are you using? : cross compile on win10/amd64(gomobile bind -o ./xxx.aar -ldflags "-s -w" -target=android) run on android arm64

go code:

    L := lua.NewState()
    defer L.Close()
    L.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
    if err := L.DoString(script); err != nil {
        log.Printf("runLua err:%v\n", err)
        return
    }

lua script:

local http = require("http")
response, error = http.request("post", "http://192.168.10.180:8086/test")

run on android got:

2020-09-05 03:54:24.675 20076-20299/org.xxx.messenger I/GoLog: runLua err:<string>:7: module http not found:
        no field package.preload['http']
        stat ./http.lua: no such file or directory
        stat /usr/local/share/lua/5.1/http.lua: no such file or directory
        stat /usr/local/share/lua/5.1/http/init.lua: no such file or directory, 
    stack traceback:
        [G]: in function 'require'
        <string>:7: in main chunk
        [G]: ?

on iOS is ok (gomobile bind -ldflags "-s -w" -o=./xxx.framework -target=ios)

littlecxm commented 2 years ago

any update? i met the same in macos well, sorry for basic mistake that L.PreloadModule must before at L.DoFile