[Top][All Lists]

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

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

From: Alexandre Becoulet
Subject: Re: [Libqtlua-list] Implementing domain model classes/tables in Lua
Date: Tue, 18 Jan 2011 00:56:57 +0100
User-agent: KMail/1.13.5 (Linux/2.6.36-ARCH; KDE/4.5.5; x86_64; ; )

On Monday, January 17, 2011 11:20:55 pm Gustavo de Sá Carvalho Honorato wrote:

> 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?

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.

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


> 3) I've started to implement this approach (source in
>, 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.


reply via email to

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