project-navigation
Personal tools

Author Topic: lua design thoughts  (Read 74319 times)

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #60 on: November 16, 2014, 10:49:38 am »
I commented out this string and now I'm able to play, but I am not sure if it wasn't a bad idea.

http://pastebin.com/t54JC339

The line you commented out should free up allocated memory. So you get a memory leak. In general, this is not a good idea. The segfault occurs due to an invalid pointer being freed. I'll look into this problem, though it may take some time since I have to port the build to my Ubuntu machine.

If I look at the backtrace I get the feeling youre running 64-bit. Correct?


Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #61 on: November 16, 2014, 11:22:30 am »
Yeah, exactly.

Btw, I am almost done with porting codeblocks project for *nix target.
« Last Edit: November 16, 2014, 11:24:50 am by Internecivus »

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #62 on: November 16, 2014, 12:39:40 pm »
I've reviewed the code and updated the repository at rxadmin. Looks like you found a true platform bug.

The code runs fine on Win32 due to the fact that floats are 32-bit. So initializing a float value to 0, and then use it as a pointer (as the code did) creates in fact a nullptr value wich is nicely ignored by Mem_Free.

On 64-bit platforms however, setting the 32-bit float to a 64-bit pointer field does not fully set the value to 0x0. So Mem_Free here tried to release the code. Thus the segfault.

The real cause here is of course the implementation of uiAbstractValueNode_t. It tries to mix cvar and floats in a single field without a flag that controls what is actually there. The code should be rewritten in the future.

Please do a pull from rxadmin/ufoai and try if the code runs. I look forward to youre comment.

xray

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #63 on: November 16, 2014, 01:13:54 pm »
Everything looks fine so far.

I'm going to help with converting ufo files to new format.

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #64 on: November 16, 2014, 01:54:24 pm »
I'm going to help with converting ufo files to new format.

Great. In that case you'll be needing a listing of the api in lua. See attacheded file for this.

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #65 on: November 17, 2014, 07:57:22 am »
I can't figure out how to derive from 'ipopup' window, can you help me?

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #66 on: November 17, 2014, 08:46:07 am »
Code: [Select]
local foo = ufo.create_window("foo", "ipopup")

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #67 on: November 18, 2014, 09:10:43 am »
Another thing is causing segfaults: when I click on my base, it will eventually segfault during deleting nodes from geoscape.
I'll provide more details as soon as I encounter it once again.

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #68 on: November 18, 2014, 01:07:42 pm »
Just looked into this. Happend on my machine also.  I've already added the fix to the repository rxadmin/ufoai. So with a pull it should be gone.

Thanx for your effort in testing.

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #69 on: November 18, 2014, 05:24:27 pm »
Another struggling point.
How to create confuncs?

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #70 on: November 18, 2014, 05:53:27 pm »
Confunc's are nodes. Create them using ufo.create_confunc. Then add an on_click eventhandler.

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #71 on: November 18, 2014, 06:43:37 pm »
Okay, seems that I still can't figure it out.

This what was before:
Code: [Select]
confunc add_mail
    {
        call *node:root.maillist.mainBody.mails@createChild("mail<1>", "mailheader")
        *node:root.maillist.mainBody.mails.mail<1>.header.index@integer = <1>
        *node:root.maillist.mainBody.mails.mail<1>.header.headline@string = <2>
        *node:root.maillist.mainBody.mails.mail<1>.icon@src = <3>
        if ( <4> eq 0 ) {
            *node:root.maillist.mainBody.mails.mail<1>.header@bgcolor   = "0.56 0.81 0.76 0.6"
        }
        *node:root.maillist.mainBody.mails.mail<1>.header.date@string = <5>
    }
and my interpretation:
Code: [Select]
add_mail = ufo.create_confunc(mailclient, "add_mail", nil)
add_mail.on_click = function(sender, index, headline, icon, state, date)
        local mail = ufo.create_control(mails, "mailheader", "mail"..index, nil)

        mail:child("header"):child("index"):set_value(index)
        mail:child("header"):child("headline"):set_text(headline)
        mail:child("header"):child("icon"):set_src(icon)
        mail:child("header"):child("date"):set_text(date)
        if (state == 0) then
            mail:child("header"):set_backgroundcolor(0.56, 0.81, 0.76, 0.6)
        end
    end

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #72 on: November 18, 2014, 08:26:55 pm »
First, can you specify the precise error you encounter?

As for the code, most of it looks okay, with exception of "set_src" that doesn't exist in lua, it was renamed to "set_source".

Also, keep in mind that if you write:
Code: [Select]
add_mail = ufo.create_confunc(mailclient, "add_mail", nil)

you create a global variable add_mail, so this identifier is shared in all modules. If in another module an identical variable "add_mail" is created the last one is preserved. So in general it is better to create module local variables using the local keyword.

Code: [Select]
local add_mail = ufo.create_confunc(mailclient, "add_mail", nil)


Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #73 on: November 18, 2014, 08:39:51 pm »
The problem is that it does nothing and I don't know how to do it propery.

Maybe it is something with arguments that I should pass to this confunc.

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #74 on: November 18, 2014, 08:49:25 pm »
Another thing.

Window 'mail' is inherited from ipopup.
It has
Code: [Select]
mail:set_closebutton(true)But I don't see any close button somehow.
And another thing is that this window takes up all place.
http://i.imgur.com/R2OKnpK.jpg - expected behavior
http://i.imgur.com/P5R8Lwm.jpg - what it really does