Modding Discussion [Suggestion] Lua string parser / eval

Discussion in 'Starbound Modding' started by iUltimateLP, Jan 1, 2016.

  1. iUltimateLP

    iUltimateLP Orbital Explorer

    Hey guys,
    I got a suggestion for Lua inside Starbound. I am currently working on a mod which allows you to write lua scripts inside the game to interact with things like wire outputs / inputs. The problem is that theres no evaluate function in this port of Lua onto Starbound, whereas the normal LUA has things like load("myAwesomeFunction()") to load a string and execute it.. This could be work-around-ed with using dofile("myTempLuaFile.lua") where I output the contents of the in-game-script editor, but dofile() does also not exist in Starbound's Lua. Theres this /eval or /entityeval command, which nearly does what I want to achieve with the script-editor. So I was around in the IRC for a bit and people kept telling me that it's quite unsafe to let players use LUA in game, as you could run functions with it which are for admins, as the eval command aswell is. So I could prevent them doing that by allowing them to just use predefined LUA modules, such as an IO module for Wiring, and stuff I get in mind. So a question to any developer who reads this: Would it be possible to add that? About security terms, I mean, if you attach a script to an object and run that script on startup, or if you run a script using dofile(), in the end, you can destroy worlds with LUA anyway..
    So, thank you for reading and answering if you do so :)
     
    Monijir likes this.
  2. TheElderScroller

    TheElderScroller Pangalactic Porcupine

    Yes, I would like access to some lua functions too....
    Also it would be nice if you could open scripted GUIs by tech scripts or items.
    And creating files, reading them, editing....
     
  3. TP_

    TP_ Title Not Found

    A return parameter on the activate callback of active items would be amazing (similar to how it works with objects atm.)
    Example:
    Code:
    function activate(fireMode, shiftHeld)
        return {"ScriptConsole", interactionConfig}
    end
    Theres some problems with this:
    Unrestricted file access is a dangerous thing and is not something that would or should happen...
    File access is fairly slow/costly process as hard drives are extremely slow in comparison to ram which could potentially lead to more lag.

    I agree that there should be a way to access/modify data from different points/parts of your mod but I think a global table that can be accessed via keys would be a nice way to do that...
    Example:
    Code:
    global.setGlobalData("MyModName", data)
    data = global.getGlobalData("MyModName")
    Edit: Btw. I agree that loadstring should be enabled!
     
    iUltimateLP likes this.
  4. iUltimateLP

    iUltimateLP Orbital Explorer

    Yep, that global data is useful, indeed! I hope any dev will read this ..
     
  5. Monijir

    Monijir Scruffy Nerf-Herder

    This is pretty far above my pay grade so grain of salt and all that. I if your general idea is executing scripts from in game - would any of the functions in this library serve as workaround? Anyway, I just wanted to suggest that you look for a workaround on github rather than trying to design one yourself.
     
  6. iUltimateLP

    iUltimateLP Orbital Explorer

    function lume.dostring(str)
    return assert((loadstring or load)(str))()
    end

    It uses loadstring or load, exactly those functions I need aswell.. Another thing which could work is lume.lambda, but that uses lume.dostring() aswell. So yeah, thanks for you work and finding this, I will note that library down, but for now, this isn't a help unfortunatelly..
     
  7. Monijir

    Monijir Scruffy Nerf-Herder

    I thought that might be the case. How about piping the log output (stderr and stdout I think) into a shell script that filters out everything but "<Script>.*</Script>" and pipes into /assets/user/scripts/blahblahscript.lua ? There are a few command line options for SB - maybe there's a way to create a makeshift temp file through the logging functionality.
     
  8. iUltimateLP

    iUltimateLP Orbital Explorer

    Hmm, not a bad idea, but if it would output stuff into the blahblahscript.lua, how to run it? Theres still no dofile(), and the require does not work somehow, and to make the script work, you would need to restart the whole game..
     
  9. Monijir

    Monijir Scruffy Nerf-Herder

    There's an admin code /reload if the database has to refresh to get the new script, if there's any justice in the world there are some options for it to not take forever. I was thinking the lua scripts would use require 'blahblahscript.lua'. The shell script would have to parse out a syntactically correct lua script. I have zero bash or batch knowledge so I'm not the guy to try it. It's a great idea though, I would think it would be a great benefit to the devs as well.
     
  10. iUltimateLP

    iUltimateLP Orbital Explorer

    Oh, I didn't knew about that reload command. Still, I haven't figured out how require works, but I will try it again. So thanks for this workaround, but still, users would need to have a batch script or something running in the background, whereas load() or loadstring(), depending on which lua version we use here is much easier and it isn't really a security problem because what you can do with load() you can also do without. Hope devs will hear my voice :D
     
    Monijir likes this.

Share This Page