[LUA] Copy file

Discussion in 'Programming' started by Incognito, Jun 28, 2014.

  1. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Is it possible to copy a file in LUA?
    Something like:
    Code:
    FS:copyFile(from, to)
     
  2. Mr.Hankey

    Mr.Hankey
    Expand Collapse

    Joined:
    Aug 9, 2012
    Messages:
    29
  3. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
  4. deject3d

    deject3d
    Expand Collapse

    Joined:
    Sep 3, 2013
    Messages:
    250
    if you're trying to accomplish this with lua from a UI app, consider using torquescript.

    this is an example from my racetimer addon that reads the name.cs of a vehicle, copying a file shouldn't be very different:

    Code:
    callLuaFuncCallback("v.vehicleDirectory", function(result) {		
    	    var getVehicleNameCode = "function readVehicleName(%path) { %fileReader = new FileObject(); %fileReader.openForRead(%path); %name = %fileReader.readLine(); %fileReader.close(); return %name; }"; // the torque code to read the file
    
    	    executeGameEngineCode(getVehicleNameCode); // insert the torque function into the engine
    
    		callGameEngineFuncCallback("readVehicleName(\""+result+"name.cs\")", function(result) { // call the torque function we just stored
    			var car_name = result.substring(result.indexOf('"')+1,result.lastIndexOf('"'));
    
    and the torque fileobject documentation: http://luisantonrebollo.github.io/Torque-3D-Wiki-Test/Torque3D script reference/classFileObject.html

    sorry if this doesn't help.
     
  5. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    Thanks. Will use pathCopy , if it is not possible with lua :)
     
  6. deject3d

    deject3d
    Expand Collapse

    Joined:
    Sep 3, 2013
    Messages:
    250
    it would be very smart to consider working around whatever problem you're trying to solve with file operations. i have a feeling that file operations will be disallowed soon... at least, they should be. right now you can do some pretty nasty things from within a mod.
     
  7. SixSixSevenSeven

    SixSixSevenSeven
    Expand Collapse

    Joined:
    Sep 13, 2013
    Messages:
    6,960
    Is this just the night where for once I agree with you. Never happens and then suddenly 3 occurrences in one night.

    File I/O if allowed at all should be sandboxed heavily. Right now it seems to have raw access across my PC file system, not good at all.
     
  8. deject3d

    deject3d
    Expand Collapse

    Joined:
    Sep 3, 2013
    Messages:
    250
    deep down, you know that i'm always right.
     
  9. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    If I need to copy the file, then solve this problem other than copying the file, impossible (backups etc).
    All mods are open source, so will be hard to hide "some pretty nasty things".
     
  10. deject3d

    deject3d
    Expand Collapse

    Joined:
    Sep 3, 2013
    Messages:
    250
    well without knowing more about how your mod works or why you need to read/write files at all, i can't really begin to think of an alternative. it's just something to consider. if someone goes on a successful virus-spreading spree, things will probably start to change.
     
  11. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    the lua is already sandboxed, but in non-enforcing mode. Do not expect this to continue to work in the future.
     
    #11 tdev, Jun 29, 2014
    Last edited: Jun 30, 2014
  12. xKryptx

    xKryptx
    Expand Collapse

    Joined:
    Aug 28, 2013
    Messages:
    102
    Nice, new features?!?! :p lol
    (100000% pure sarcasm)
     
  13. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    rather lack of sleep and being overloaded
     
  14. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,683
    Have you tried turning it on and off again? :p
     
  15. xKryptx

    xKryptx
    Expand Collapse

    Joined:
    Aug 28, 2013
    Messages:
    102
    All good mate, I for one appreciate the hard work you and the team are doing on this, a very humungous cheers :)
    But please do not work too hard that you fizzle out for your personal lives.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice