Hoeloe wrote: ↑Wed May 19, 2021 8:19 pm
By making these changes you're not going to be able to do this and also share anything you make with it. The purpose of lockdown.lua is, as the name suggests, to lock down the things LunaLua can load in order to prevent people from building malware in SMBX (which is extremely possible with access to the filesystem and luasocket, it's very easy to do).
I understand this and figured as much. The changes made in my version of lockdown.lua are for private use. For example, sharing an SMBX project in development with other individuals (not publically shared) while utilizing an auto-update feature as mentioned allows for a more efficient way of synchronizing newer versions and changes before I feel it's polished enough for release. That hypothetical public release version would not include changes to lockdown or the update system... It's mostly just an independent hobby, and I'm asking for the sake of understanding SMBX's Lunalua potential, not to steal anyone's credit card information. (Though I completely understand the security concern.)
I will mention that while luasocket's functionality is limited without changes to lockdown.lua, much of it is still useful regardless, like connecting two devices for the exchange of data for online multiplayer. (I did need to change main.lua to require socket.core at 7 different places first.) While I've gotten some form of this to work through LAN, I needed away to connect through global ip (similar to how Minecraft servers work, still within security-conscious reason), and the following code worked for me, after manually downloading luasocket as a folder within an SMBX episode and tweaking its .lua src scripts' loaded APIs/"require":
Code: Select all
-- Slight modification of Thijs's code, giving an error of your global ip using ipinfo.io:
local socket = require("socket.core")
local http = require("luasocket/src/http")
local ltn12 = require("luasocket/src/ltn12")
local json = require("ext/lunajson")
local resp,code,headers,status = http.request("http://ipinfo.io/json")
if tostring(code) == "permission denied" then error("Something is preventing this game from accessing the internet--most likely your firewall. To play online, change your firewall's settings to allow smbx.exe.") end
if code ~= 200 then return nil, "Failed fetching external IP; "..tostring(status) end
local data, err = json.decode(resp)
if not data then
return nil, "Failed fetching external IP; "..tostring(err)
end
if data.ip then
error(tostring(data.ip))
else
return nil, "Failed fetching external IP; no ip field was returned"
end
_____________________________________________________________________________________________________________________
Hoeloe wrote: ↑Wed May 19, 2021 8:19 pm
I believe LunaLua can absolutely require .dll files (SMBX2 used to have one in its core files), but from what I understand, Lua can't just load any .dll you like, it requires it to be built from Lua bytecode. As for jit.util, I'm pretty sure that's part of the Lua core, since that's part of the JIT compiler. I am pretty certain it is not possible to load a C library using Lua, regular or otherwise. We can access C code from LunaDLL, but not arbitrary libraries by my understanding of how things are set up.
Thanks for your answers, that's very helpful. After seeing your comments, I reinvestigated the following Lua documentation pages:
https://www.lua.org/pil/8.2.html
https://www.lua.org/pil/26.2.html
I'm still a bit confused, because it claims on the one hand: "Unlike packages written in Lua... C packages need to be loaded and linked with an application before use." But then on the other hand: "Lua provides all the functionality of dynamic linking in a single function, called loadlib."
I tried running a .dll using loadlib to test this, and my code looked like this:
Code: Select all
local path = Misc.resolveDirectory("luafilesystem/src").."/lfs.dll"
local f = assert(package.loadlib(path, "luaopen_lfs"))
f()
However, the error message I got back was that "loadlib" was a nil function. I tried it as package.loadlib and just loadlib, and neither worked. The second documentation page does state "The most convenient way to do it is with the dynamic linking facility,
if your Lua interpreter supports this facility," so perhaps SMBX does not support dynamic linking like this, which is why the loadlib function won't work within a Lua file, because it has to be pre-loaded elsewhere? Tutorials such as this one (
https://blog.devgenius.io/how-to-add-yo ... fd246f0fa8) seem to indicate that .so and .dll file types should be loadable through "require" same as .lua files, though of course, I'm a novice at all this so I'm probably misunderstanding Lua or am mistaken.