beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
219 stars 101 forks source link

Luasocket spills vars into global namespace #1227

Open sprunk opened 9 months ago

sprunk commented 9 months ago

https://github.com/beyond-all-reason/spring/blob/20f996f016156d1241884ba63abbc797456c7959/rts/lib/luasocket/src/socket.lua#L55-L58 https://github.com/beyond-all-reason/spring/blob/20f996f016156d1241884ba63abbc797456c7959/rts/lib/luasocket/src/socket.lua#L88 https://github.com/beyond-all-reason/spring/blob/20f996f016156d1241884ba63abbc797456c7959/rts/lib/luasocket/src/socket.lua#L38 https://github.com/beyond-all-reason/spring/blob/20f996f016156d1241884ba63abbc797456c7959/rts/lib/luasocket/src/socket.lua#L128

These vars get exposed to LuaUI as globals, they aren't actually under the socket namespace. (Obviously the socket global is fine.)

ahhnevermore commented 9 months ago

Hi, I will be taking up this issue as my first issue. Could you tell me some steps to reproduce the error you faced?

sprunk commented 9 months ago

No error, the vars just aren't nil.

Step 1) do the equivalent of this https://github.com/ZeroK-RTS/Zero-K/commit/1668eb5e3ee5000410735cd2f9876860eacdbd14 (note that this is LuaUI global scope; not the "global" scope of an individual widget; and not unsynced LuaRules) Step 2) notice that the variables aren't nil

ahhnevermore commented 9 months ago

I tried to reproduce this problem using the following steps:

  1. I used the metal factions game with the Barren map
  2. I put Spring.Echo(sourcet, sinkt, BLOCKSIZE) into a widget which I placed in luaui/widgets
  3. The result was nil,nil,nil

I am unsure whether I have to download ZeroK to check further or if I have got some steps wrong in this process. Could you clarify?

sprunk commented 9 months ago

I put Spring.Echo(sourcet, sinkt, BLOCKSIZE) into a widget which I placed in luaui/widgets

You have to modify something in the global LuaUI scope, so a widget won't do because they use their own scope. If you're testing with Metal Factions then I think you can put the echo at the top of ./LuaUI/mfwidgets.lua.

ahhnevermore commented 9 months ago

image

not too sure if thats correct place where it should be outputted, but I put Spring.Echo(sourcet, sinkt, BLOCKSIZE) in mfwidgets.lua and in the initial scroll nil,nil,nil as seen in the image

sprunk commented 9 months ago

Looks like the correct place. Perhaps find infolog.txt (should be in the same folder as spring.exe), it contains the same log as above. Then Ctrl+F "LuaSocket Support", if it says "Enabled" then I'm not sure what's wrong. If it says "Disabled" then you can add LuaSocketEnabled=1 to your springsettings.cfg and try again.

ahhnevermore commented 9 months ago

LuaUI Entry Point: "luaui.lua" [t=00:00:19.187013][f=-000001] LuaSocket Support: enabled [t=00:00:19.189155][f=-000001] Error: Error loading socket.lua [t=00:00:19.204883][f=-000001] [CAS::GASCB] Archive file="barren.sd7" cs="50109b2e799bc85ef16b538f607fadd17b988664c55f7606401ba1507f90c9489804481a4c89979d6a3ddd43f8464c0cf6d420f867912397211800c26b17f313" [t=00:00:19.204967][f=-000001] [CAS::GASCB] Archive file="maphelper.sdz" cs="3fe8166f5a6d8c1a0340a80fbe2a46d5fcbd1289266e7e981a96f7816c80bec7d34e4d111d88e6f6b98fc58fedfb3dc73e178c1edb6f67d1cfb8f83729b89855" [t=00:00:19.205146][f=-000001] [CAS::GASCB] Archive file="metal_factions.sdd" cs="bdabea32c02d24622869473203deab9efacb02ec9036b3e31471079fa3b6964cf04847bc6530f69d8ec7b4b3fc05afec690b4de77dc2c1b557d893924d08fd95" [t=00:00:19.205232][f=-000001] [CAS::GASCB] Archive file="springcontent.sdz" cs="9579ba863e4281b096f5375c12fdcd537e22f8e579024e08152359dc90769cb2e5641d731d2b18f2e7d140f041a65824890758117b6b2e93430d3f4e9208773b" [t=00:00:19.205299][f=-000001] [CAS::GASCB] Archive file="bitmaps.sdz" cs="9f8677def4972d2acd13c904d99c6c318e30223611fb886f77ec6637690a4d57fbc71074cfeb8b4541ffb4764243bdc7c53cca09d2fbeda10fb7de60b89e4af1" [t=00:00:19.206042][f=-000001] Using LUAUI_DIRNAME = luaui/ [t=00:00:19.206672][f=-000001] Reloading GUI config from file: luaui/ctrlpanel.txt [t=00:00:19.232204][f=-000001] nil, nil, nil [t=00:00:19.241731][f=-000001] LuaUI: bound F11 to the widget selector [t=00:00:19.241747][f=-000001] LuaUI: bound CTRL+F11 to tweak mode

in infolog.txt this seems relevant I suppose. Any reason why luasocket isnt working

sprunk commented 9 months ago

From what you pasted:

[t=00:00:19.187013][f=-000001] LuaSocket Support: enabled
[t=00:00:19.189155][f=-000001] Error: Error loading socket.lua
[t=00:00:19.204883][f=-000001] [CAS::GASCB] Archive file="barren.sd7"

The "error loading socket.lua" looks relevant!