Sign in to follow this  
apefish

Lua syntax error

Recommended Posts

Hi, I have this piece of lua code that i wrote that has a syntax error but i can't figure it out: function new_scenemanager() return { function setstart(self, startscene, ...) return self.current = startscene(self, ...) end function switch(self, newscene, ...) self.current:unload() return self.current = newscene(self, ...) end function run(self) while self.current:update() do end --update returns false to close the application self.current:unload() end } end The lua interpreter complains about line 3; "'(' expected near 'setstart'". The problem is that there is already a '(' near 'setstart' so i don't know why it's complaining. If i change it to "setstart = function(self, startscene, ...)" it complains about not having an 'end' to close the function. If anyone can spot what the problem is that would be great.

Share this post


Link to post
Share on other sites
hmmm..

You're sure that you wrote the code? Not calling you a liar, but (I may be mistaken) the code has some newbie errors, and at the same time is a little complex..



the new_scenemanager function returns a table, but you don't put a ',' between elements.

why don't you do something like:

local MT={}

function MT.setstart(self, startscene,...)

blabla
end

function MT.switch
....

function new_scenemanager()
return MT
end




also:
function setstart(self, startscene, ...)
return self.current = startscene(self, ...)

it should be something like:

function setstart(self, startscene, ...)
return self.current = startscene(self, args)

Share this post


Link to post
Share on other sites
Thanks for the tip on the commas, what a dumb mistake. Yes i did write this code and i am a lua n00b (hence the lack of commas).

As for the ... vs args I don't know; in the reference it says ... is the new way to do it (Lua 5.1), but then of course there's nothing about it in the books you can get online.

hmmm. If Lua can't do that return it's a bit disturbing, I'll experiment. I'm used to C where everything is an expression.

Thanks alot for your tips, I'll see If i can get it working now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this