libqtlua-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libqtlua-list] Implementing domain model classes/tables in Lua


From: Gustavo de Sá Carvalho Honorato
Subject: Re: [Libqtlua-list] Implementing domain model classes/tables in Lua
Date: Mon, 17 Jan 2011 23:43:54 -0200

On Mon, Jan 17, 2011 at 9:56 PM, Alexandre Becoulet
<address@hidden> wrote:
> On Monday, January 17, 2011 11:20:55 pm Gustavo de Sá Carvalho Honorato wrote:
>
> Hi,
>
>> I've mentioned in previous e-mails that I would like to implement the
>> bussiness logic of my application using Lua language because of its
>> facilities. However, I would like to access my model classes in Lua
>> and C++ in an easy way for both sides. One idea I have for doing this
>> is to create wrappers in C++ which delegates all getters/setters and
>> methods to the Lua table stored in a Value object inside my wrapper
>> class, but I'm having some doubts:
>
>> 1) Do you think that creating this wrappers/delegators is a good
>> approach? Any suggestions?
>
> Did you had a look to QtLua MVC classes?
Yes.
>
> This is what they have been developped for. Item, ItemList... are designed to
> implement a tree structure which can be accessed from both lua and Qt
> tree/list view. Data is stored in user C++ classes which inherit from Item and
> ItemList. This is really powerfull, view are updated in realtime when you
> manipulate data from lua. This is the best approach to me because lua script
> is only used to extend the application and is not involved in storing data.
> Support for table/grid structure is still missing.

Unless I'm missing some important point, in my case I think QtLua MVC
does not apply very well. My models need to be presented in many forms
of views (timeline, graphicsview, table, tree, etc). Your application
seems to present, in most of the time, data in tabular or tree format,
right?

>
> Other classes allow accessing data stored in lua tables with tree or table
> view. This is less powerfull than the first approach because we have no way to
> detect changes to lua tables from lua to update the views.
>
>> 2) What is the difference between Value and ValueRef? I suspect that
>> Value is a copy of a Lua data, so, if I change something in a Value
>> object using C++ code it won't reflect in Lua VM. Using ValueRef it
>> will reflect. In this manner, the correct way to implement my wrappers
>> is using ValueRef, right?
>
> Value is not a copy, it's stored in the Lua VM.
>
> ValueRef acts as a reference to a lua value in a table (because all lua values
> in the vm are in some kind of table). It holds two lua values, the table (or
> userdata) and the key. When you assign a ValueRef it will write in table[key].
>
> see http://www.nongnu.org/libqtlua/manual/ValueRef_class_reference.html
>
>> 3) I've started to implement this approach (source in
>> http://pastebin.com/UtSepwTT), but I'm stuck with an error. In line
>> 62, when I try to read the table size property with  return
>> value["size"]; I'm getting the following error: "Can not make value
>> reference with lua::nil type as table.". Could you help me?
>
> The ValueRef was instanciated empty, its table value is nil.

I didn't understand. I've initialized ValueRef in line 53. Did you notice that?

>
> --
> Alexandre
>
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]