Results 1 to 4 of 4

Thread: Execute string

  
  1. #1
    skyd1v3r is offline -Hacks Newbie
    Join Date
    Oct 2005
    Posts
    3
    Rep Power
    0

    Default

    Hallo, I found this in the manual:

    Code:
    • loadstring (string [, chunkname])
    Loads a string as a Lua chunk (without running it). If there are no errors, returns the compiled
    chunk as a function; otherwise, returns nil plus the error message. The environment of the returned
    function is the global environment.
    The optional parameter chunkname is the name to be used in error messages and debug information.
    To load and run a given string, use the idiom
    assert(loadstring(s))()
    I did not manage to use it.
    If I got

    string="mycode"

    how can I execute mycode ?

    Thanks


  2. #2
    modsyn is offline -Hacks Guru
    Join Date
    Aug 2005
    Location
    Shinigami Kurosaki Ichigo!
    Posts
    2,475
    Rep Power
    17

    Default

    you know, it's sad. i couldn't find anything easy for that either.
    i found the os.execute( command ), but that doesn't help at all.
    the only thing i could think of is writing the string to FILE and then
    calling dofile(FILE). that's probably not the answer you wanted, but
    it's about the best i can do...
    jMEnc Guide, jMEnc2 page - by the way, you smell nice

  3. #3
    skyd1v3r is offline -Hacks Newbie
    Join Date
    Oct 2005
    Posts
    3
    Rep Power
    0

    Default

    You propably helped me more than you might belive :rolleyes:
    I wanted to know how to execute a string since I found no way to write it to a file. So, how can I save a string to an executeable .LUA file?
    (eah... and can I manipulate WHERE in the file it is should apear?)

    Thanks
    skyd1v3r

  4. #4
    modsyn is offline -Hacks Guru
    Join Date
    Aug 2005
    Location
    Shinigami Kurosaki Ichigo!
    Posts
    2,475
    Rep Power
    17

    Default

    a .lua file isn't an executable file at all. it's just an interpreted script.
    but here's how you can write to a file and subsequently execute that
    file:


    Code:
    mycode = "screen:save("screen.png")"
    myLUAfile = "do_me.lua"
    outf = io.open(myLUAfile,"w")
    if outf then --happy
      outf:write(mycode)
      outf:close()
    end
    dofile(myLUAfile)
    please not that i haven't tested this code. it's just a suggestion. there
    might be some tweaking or unexpected bugs for it to work.
    jMEnc Guide, jMEnc2 page - by the way, you smell nice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •