AggrorJorn Posted May 28, 2010 Share Posted May 28, 2010 Does abybody have experience in compiling a Lua script to a luac luac file? I found which explains it a little but the I only get errors. http://www.lua.org/manual/4.0/luac.html so far I have: file = io.open("save.lua","w") --Open in Write mode file:write("test") file:close() luac -o save.lua save.luac Quote Link to comment Share on other sites More sharing options...
Rick Posted May 28, 2010 Share Posted May 28, 2010 Just curious, why are you opening, writing, then closing the file? Have you tried just running the luac command you have there at the end against a lua file you already have? This gives me a cool idea though. Would be pretty cool to dynamically create lua files on the fly in a game. Quote Link to comment Share on other sites More sharing options...
ESP Posted May 28, 2010 Share Posted May 28, 2010 I think that is what he is trying to do. Is 'test' a valid LUA command? Robin Quote Programmer , Intel Quad core, NVIDIA GeForce GT 220, Windows 7 Pro, Galaxy Tab 2 ( 7" and 10"), LE2,LE3,3DWS Link to comment Share on other sites More sharing options...
Rick Posted May 28, 2010 Share Posted May 28, 2010 Oh yeah. Looks like he's trying to save out saved game data if I had to guess with his lua filename. I was thinking of something that had functionality instead of just data, but yeah same idea. ESP gives a good point. I assume you can only compile a lua file that is valid lua syntax. Quote Link to comment Share on other sites More sharing options...
Guest Red Ocktober Posted May 28, 2010 Share Posted May 28, 2010 A... are you trying to compile a script file to an executable... in the script editor i simply click on Tools/Compile... the result is a luac file that can be executed as long as luac.exe is in the path... or... are you trying to invoke the luac compiler from within a running luac program? --Mike Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 28, 2010 Author Share Posted May 28, 2010 Well I am looking into savegames and settings saving. At the moment I am writing my test variable value to the save.lua file. However, I don;t want people do change that lua file. That is why I want to convert it to luac. require("Scripts/constants/engine_const") --registering the abstract path RegisterAbstractPath("") --Set a graphics mode Graphics(800,600) --Framework object fw = CreateFramework() --set camera camera = fw.main.camera camera:SetPosition(Vec3(0,2,-10)) test = 1 --main function while KeyHit(KEY_ESCAPE)==0 do if KeyHit(KEY_1)==1 then test = 1 elseif KeyHit(KEY_2)==1 then test = 2 elseif KeyHit(KEY_3)==1 then test = 3 end --Open the save.lua file if KeyHit(KEY_O)==1 then dofile("abstract::save.lua") end --Write the test value in save.lua if KeyHit(KEY_S)==1 then file = io.open("save.lua","w") --Open in Write mode if file == nil then Notify("there is no file") end file:write("test = " .. test) file:close() end fw:Update() fw:Render() SetBlend(1) DrawText(" Use 1, 2 and 3 to set value",0,30) DrawText(" S = saving - O = open",0,60) DrawText(test,0,90) SetBlend(0) Flip(0) end Quote Link to comment Share on other sites More sharing options...
Rick Posted May 28, 2010 Share Posted May 28, 2010 So does the above work for you because I notice you now have test = a value instead of just test. I would think test = value would be valid. You might be better off making a lua file by hand to be how you think you want it, then try compiling manually with luac to see what errors you get. Once you get that worked out, then you can make the file with code. But you can't just do "luac -o save.lua save.luac" inside a lua file. luac is an exe and to kick off an exe from lua you need to use os.execute("c:\\temp\\program.exe"). This is Windows specific I think, but that shouldn't be an issue right now. Quote Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Share Posted May 28, 2010 Aggror, If it helps, I use this method all the time but I save and read from a text file. --Record Scene4 io.output(io.open("Txts/scene.txt","w")) io.write("01") io.close() This code will create a text file called scene.txt and write a line which says '01'. If the value changes it will overwrite the file, eg. '02'. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 28, 2010 Author Share Posted May 28, 2010 The code I posted works fine actually. The program stores the values and loads it back how I would expect it to be. The only problem is that anyone can open the lua file with an editor. Can I use some other kind of file to store my data in and secure this file so that no one can access it? Quote Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Share Posted May 28, 2010 Sorry, misunderstood. AndyGFX says he has a data file solution here.. Haven't explored it but.... Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 29, 2010 Author Share Posted May 29, 2010 Thanks for the link. But I think you have to run this command outside the script. When your data are static, then is possible compile file to binary format: luac -o game.data game.lua, but then you don't forget change filename in your code, when output filename isn't same. Besided LUAC is there another way to secure your save data? Quote Link to comment Share on other sites More sharing options...
Rick Posted May 30, 2010 Share Posted May 30, 2010 If you google for something like Lua encryption I'm sure someone has created some encryption library for Lua that you can use. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 30, 2010 Author Share Posted May 30, 2010 AndyGFX gave me a good answer: http://leadwerks.com/werkspace/index.php?/topic/1853-howto-using-lua-script-as-data-file/page__p__18993entry18993 os.execute("luac -o save.data save.lua") Quote Link to comment Share on other sites More sharing options...
Rick Posted May 30, 2010 Share Posted May 30, 2010 Oddly enough so did I above. Maybe it was hiding. But you can't just do "luac -o save.lua save.luac" inside a lua file. luac is an exe and to kick off an exe from lua you need to use os.execute("c:\\temp\\program.exe"). This is Windows specific I think, but that shouldn't be an issue right now. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 30, 2010 Author Share Posted May 30, 2010 oops sorry Rick. Must have skipped it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.