Jump to content

Compiling via lua script


AggrorJorn
 Share

Recommended Posts

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest Red Ocktober

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'.

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...