Table Problems Is it Lua JIT?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Table Problems Is it Lua JIT?

Post by Ekamu »

Is there anything different with how Lua JIT uses tables?
I tried running this code but it says theres an error in main, line 4, y is a nil value.

I know C, so what am I doing wrong? Try running this code as your love.main

Code: Select all

function love.load()
    screen = {}
    screen.x  = 100,
    screen.y  = 5,
    screen.w  = 600,
    screen.h  = 400,
    
    msg = {}
    msg.x  = 0,
    msg.y  = 405,
    msg.w  = 800,
    msg.h  = 160,
    
    face = {}
    face.x = 5,
    face.y = 5,
    face.w = 96,
    face.h = 96,
    
    stat = {}
    stat.x = 700,
    stat.y = 5,
    stat.w = 96,
    stat.h = 400, 
end

function love.update(dt)    
end

function love.draw()
    love.graphics.rectangle("line", screen.x, screen.y, screen.w, screen.h)
    love.graphics.rectangle("line", msg.x, msg.y, msg.w, msg.h)
    for i = 1, 4 do 
    love.graphics.rectangle("line", face.x, (i*face.y), face.w, face.h)
    end
    love.graphics.rectangle("line", stat.x, stat.y, stat.w, stat.h)
end
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Table Problems Is it Lua JIT?

Post by zorg »

you only need to use commas (,) if you put your members into the table definition, not do it externally. Let me show you what i mean:

Code: Select all

Table = {
  v1 = 5,
  v2 = 'h',
  -- etc...
}
vs.

Code: Select all

Table = {}
v1 = 5
v2 = 'h'
-- etc
Basically, to the parser, it seemed that you tried to do

Code: Select all

screen.x = 4, screen.y
so it tried to access screen.y on the 4th line, and failed.
In short, remove those commas.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

Re: Table Problems Is it Lua JIT?

Post by Ortimh »

Or you can do it with commas.

Code: Select all

screen.x, screen.y = 100, 5
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Table Problems Is it Lua JIT?

Post by Ekamu »

Im guessing callback functions are written just like C right?

function love.load() {

}

or

function love.load [

]

???

Ill read this tutorial. http://cellux.github.io/articles/introd ... it-part-1/
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Table Problems Is it Lua JIT?

Post by zorg »

That tutorial is mixing the C api part with the lua part in, as far as i see it. (since it assumes you writing the c part of your code as well; with love, that's a bit moot)
And if you want callback functions in lua, then you do it the usual way:

Code: Select all

function callback(params)
--...
end

-- or

callback = function(params)
--...
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Ekamu
Party member
Posts: 178
Joined: Fri Sep 20, 2013 11:06 am

Re: Table Problems Is it Lua JIT?

Post by Ekamu »

So do we have any arguments (paramas) that are new with the basic load, update and draw callbacks.

This is LuaJIT 2.0.3 Im guessing?

Code: Select all

local accent_maps = {
   hu = {
     ['á'] = 'a',
     ['é'] = 'e',
     ['í'] = 'i',
     ['ó'] = 'o',
     ['ú'] = 'u',
     ['ö'] = 'o',
     ['ü'] = 'u',
     ['ő'] = 'o',
     ['ű'] = 'u',
   },
}
EDIT: This works now. I got rid of the syntax sugar. now its JIT. (^_^)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 219 guests