uspgamedev / luasteam

Bindings to connect lua with Steam API
https://luasteam.readthedocs.io/en/stable/
MIT License
129 stars 23 forks source link

Releasing on MacOS #14

Closed GeorgeA93 closed 1 month ago

GeorgeA93 commented 3 years ago

Hello! I am trying to build my game for release on macos. Following the 'Creating a macOS Application' steps here: https://love2d.org/wiki/Game_Distribution

My game runs fine before building, but if I try to run the actual built game I get the follow error:

Error

main.lua:1: module 'luasteam' not found:
no field package.preload['luasteam']
no 'luasteam' in LOVE game directories.
no file 'luasteam' in LOVE paths.
no file './luasteam.lua'
no file '/usr/local/share/luajit-2.0.5/luasteam.lua'
no file '/usr/local/share/lua/5.1/luasteam.lua'
no file '/usr/local/share/lua/5.1/luasteam/init.lua'
no file './luasteam.so'
no file '/usr/local/lib/lua/5.1/luasteam.so'
no file '/usr/local/lib/lua/5.1/loadall.so'

Traceback

[C]: in function 'require'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'

I have tried placing the luasteam.so in the different directories inside my game, but to no avail.

I think this has something to do with how love is loading (or not loading) libraries in fused mode, but I am a bit stumped as to how to proceed from here.

rilifon commented 3 years ago

Hi there George!

Have you tried putting luasteam.so on the same root folder as your .app? I believe this was our solution when we used luasteam on a OSX binary release in a project a few years ago, please try to see if it works and update us in any case

GeorgeA93 commented 3 years ago

Hi there George!

Have you tried putting luasteam.so on the same root folder as your .app? I believe this was our solution when we used luasteam on a OSX binary release in a project a few years ago, please try to see if it works and update us in any case

Hi rilifon! Gave that a go, and it still gives me the same error.

GeorgeA93 commented 3 years ago

On that note, its also worth noting im not sure where I need to place the libsteam_api.dylib too. This might be a combined issue?

GeorgeA93 commented 3 years ago

Okay I managed to get a somewhat hacky approach to this working. If I modify the package.cpath in lua to search for the current source directory like so:

local dir = love.filesystem.getSourceBaseDirectory()
package.cpath = package.cpath .. ';' .. dir .. '/?.so'

And put the luasteam.so and the libsteam_api.dylib inside of MyApp.app/Contents/Resources it works!

But I am not stoked about this approach, it feels rather wrong to have to do this. Can I get any confirmation this is an OK thing to do or will I run into issues when actually distributing the app...?

yancouto commented 3 years ago

Hey @GeorgeA93 !

I'm afraid that's the solution to be able to place the library next to the love file, and it is indeed what we have done in our game in which we use luasteam (and for which we created luasteam :D)

Check it out here: https://github.com/MarvellousSoft/MarvInc/blob/e914dcd15d7b538793c7dcac27d3350d716d47db/marv/main.lua#L10-L13

This is definitely ok to do. It is something we could explain on the "Getting Started" wiki for this repo.

GeorgeA93 commented 3 years ago

Hi @yancouto good to see someone else is doing the same thing! I'd be happy to submit a PR which adds this to the Getting Started section. Would deffo help a lot of people out!

My final question, why is this needed? What is the difference about running it as a mac app vs running it via love. The cpath is the same in both scenarios?

I can close out this issue with the PR to add the docs, unless you want to close now.

yancouto commented 3 years ago

It has to do with how love sets up cpath when running lua, in both fused and unfused binaries. This thread has some more info about that. It might be possible to not set the cpath but this was a consistent way to do it across platforms I found, and I haven't look much deeper into that.

I would be glad to review a PR with those changes, no need to close the issue now :)

yancouto commented 1 month ago

The link to the "hack" is now in the Getting Started section.