Picon

Re: new project added

> Maybe you could think in putting a more explicit note about manual's
> license terms

Done. I hope it's clear now:
	Copyright © 2006 Lua.org, PUC-Rio.
	Freely available under the terms of the Lua license.

--lhf

Rici Lake | 1 Dec 2006 01:52

Re: [OT] Re: Lua 5.1 reference manual in Vim


On 29-Nov-06, at 7:09 PM, Luis Carvalho wrote:

> That's because the 'iskeyword' option is set differently for help  
> files, and
> it includes '(' (\lr should work fine in C/Lua code). To fix that, you  
> can
> append "set iskeyword+=^(" to after/syntax/help.vim.

I tried that and it didn't work (on vim 6.2, maybe it's different on  
vim 7).

Hence my suggestion to use this bit of vimscript:

map <silent> <F1> :call  
<SID>LookUp(matchstr(strpart(getline("."),matchend(strpart(getline("."), 
0,col(".")),".*\\W\\w")-1),"\\w*"))<CR>

Luis Carvalho | 1 Dec 2006 03:42

Re: [OT] Re: Lua 5.1 reference manual in Vim

> I tried that and it didn't work (on vim 6.2, maybe it's different on  
> vim 7).

True. It worked for me on Vim 6.4 and 7.0, but not on 6.3. I think it might be
easier to convince users to upgrade than to find a general fix. :)

> Hence my suggestion to use this bit of vimscript:
> 
> map <silent> <F1> :call  
> <SID>LookUp(matchstr(strpart(getline("."),matchend(strpart(getline("."), 
> 0,col(".")),".*\\W\\w")-1),"\\w*"))<CR>

That's a good one. I try not to bind "usually preferred" keys since this tends
to get annoying for many users. Believe me: key bindings are a religious
matter in some parts of the globe (not to mention editor choice). :)

Cheers,
Luis.

-- 
A mathematician is a device for turning coffee into theorems.
        -- P. Erdos 

--

-- 
Luis Carvalho
Applied Math PhD Student - Brown University
PGP Key: E820854A <carvalho <at> dam.brown.edu>

wang xu | 1 Dec 2006 06:31
Picon

linked variable

Hi Lua gurus,

Is there a way to implement a linked variable?

For example

$ lua
Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> var1="hello"
> var2=var1
> var2="world"
> =var1
hello
>

I want var1 changed to "world" too, when I change var2.

I tried to store the string "var1" in some place, and when I want to change var1, I use:

> _G["var1"]="world"
> =var1
world
>

It works, but It doesn't work for variable inside tables, for example:

> var1={var3="hello"}
> _G["var1.var3 "]="world"
> =var1.var3
hello
>

Is there a generic way to automatically update one variable when the value of another variable is changed?

Regards,
Austin

Rici Lake | 1 Dec 2006 07:01

Re: linked variable


On 1-Dec-06, at 12:31 AM, wang xu wrote:

> Is there a generic way to automatically update one variable when the 
> value of another variable is changed?

No. (And why do you want to do that?)

The closest you can do is to implement your own "boxed" values, using 
tables with a single key (say, 1):

val1 = {"a"}
val2 = val1
val1[1] = "b"
=val2[1]

You could dress it up in O-O notation:

do
   local meta = {}
   meta.__index = meta
   function meta:set(v) self[1] = v end
   function meta:get() return self[1] end

   function Box(v)
     return setmetatable({v}, meta)
   end
end

val1 = Box("a")
val2 = val1
=val2:get()
val1:set("b")
=val2:get()

wang xu | 1 Dec 2006 08:24
Picon

Re: linked variable

Hi Rici,

Thanks for the reply!

See my comments below.


2006/12/1, Rici Lake <lua <at> ricilake.net>:

On 1-Dec-06, at 12:31 AM, wang xu wrote:

> Is there a generic way to automatically update one variable when the
> value of another variable is changed?

No. (And why do you want to do that?)


I have a View, the view is a Text Widget, which has an attribute "str", when the str is modified, the Text widget will update the Screen with the string.

I also have a Model, which is a table containing many strings, each string is corresponding to one Text Widget.

What I want to do by a linked variable are:
1) when a string in the model changes, the str in the view update automatically.
2) when the str in the Text Widget changes(by the user through GUI), the sting in the Model table update automatically too.

The closest you can do is to implement your own "boxed" values, using
tables with a single key (say, 1):

val1 = {"a"}
val2 = val1
val1[1] = "b"
=val2[1]

You could dress it up in O-O notation:

do
   local meta = {}
   meta.__index = meta
   function meta:set(v) self[1] = v end
   function meta:get() return self[1] end

   function Box(v)
     return setmetatable({v}, meta)
   end
end

val1 = Box("a")
val2 = val1
=val2:get()
val1:set("b")
=val2:get()


Yeah. that's a way. but I need to change my model and widget implementation...

I came from the TCL world, and there is a tracevar can do this, so I'm wondering if Lua has similar functionality..

askok | 1 Dec 2006 09:15
Gravatar

Re: linked variable


Shouldn't the Text View be using the Model, instead of 
caching the strings?

Are the View & Model made in C(++) or in Lua?

On Fri, 1 Dec 2006 15:24:51 +0800
  "wang xu" <xu4wang <at> gmail.com> wrote:
> Hi Rici,
> 
> Thanks for the reply!
> 
> See my comments below.
> 
> 
> 2006/12/1, Rici Lake <lua <at> ricilake.net>:
>>
>>
>> On 1-Dec-06, at 12:31 AM, wang xu wrote:
>>
>> > Is there a generic way to automatically update one 
>>variable when the
>> > value of another variable is changed?
>>
>> No. (And why do you want to do that?)
> 
> 
> 
> I have a View, the view is a Text Widget, which has an 
>attribute "str", when
> the str is modified, the Text widget will update the 
>Screen with the string.
> 
> I also have a Model, which is a table containing many 
>strings, each string
> is corresponding to one Text Widget.
> 
> What I want to do by a linked variable are:
> 1) when a string in the model changes, the str in the 
>view update
> automatically.
> 2) when the str in the Text Widget changes(by the user 
>through GUI), the
> sting in the Model table update automatically too.
> 
> The closest you can do is to implement your own "boxed" 
>values, using
>> tables with a single key (say, 1):
>>
>> val1 = {"a"}
>> val2 = val1
>> val1[1] = "b"
>> =val2[1]
>>
>> You could dress it up in O-O notation:
>>
>> do
>>    local meta = {}
>>    meta.__index = meta
>>    function meta:set(v) self[1] = v end
>>    function meta:get() return self[1] end
>>
>>    function Box(v)
>>      return setmetatable({v}, meta)
>>    end
>> end
>>
>> val1 = Box("a")
>> val2 = val1
>> =val2:get()
>> val1:set("b")
>> =val2:get()
>>
>>
> Yeah. that's a way. but I need to change my model and 
>widget
> implementation...
> 
> I came from the TCL world, and there is a tracevar can 
>do this, so I'm
> wondering if Lua has similar functionality..

wang xu | 1 Dec 2006 10:15
Picon

Re: linked variable

Yeah..It's possible for the View to use the data inside the model.
I guess I have to use the method Rici pointed out. A.K.A using a table to hold a string.

Both the Model and the View are in Lua.

2006/12/1, askok <at> dnainternet.net < askok <at> dnainternet.net>:

Shouldn't the Text View be using the Model, instead of
caching the strings?

Are the View & Model made in C(++) or in Lua?


On Fri, 1 Dec 2006 15:24:51 +0800
  "wang xu" < xu4wang <at> gmail.com> wrote:
> Hi Rici,
>
> Thanks for the reply!
>
> See my comments below.
>
>
> 2006/12/1, Rici Lake < lua <at> ricilake.net >:
>>
>>
>> On 1-Dec-06, at 12:31 AM, wang xu wrote:
>>
>> > Is there a generic way to automatically update one
>>variable when the
>> > value of another variable is changed?
>>
>> No. (And why do you want to do that?)
>
>
>
> I have a View, the view is a Text Widget, which has an
>attribute "str", when
> the str is modified, the Text widget will update the
>Screen with the string.
>
> I also have a Model, which is a table containing many
>strings, each string
> is corresponding to one Text Widget.
>
> What I want to do by a linked variable are:
> 1) when a string in the model changes, the str in the
>view update
> automatically.
> 2) when the str in the Text Widget changes(by the user
>through GUI), the
> sting in the Model table update automatically too.
>
> The closest you can do is to implement your own "boxed"
>values, using
>> tables with a single key (say, 1):
>>
>> val1 = {"a"}
>> val2 = val1
>> val1[1] = "b"
>> =val2[1]
>>
>> You could dress it up in O-O notation:
>>
>> do
>>    local meta = {}
>>    meta.__index = meta
>>    function meta:set(v) self[1] = v end
>>    function meta:get() return self[1] end
>>
>>    function Box(v)
>>      return setmetatable({v}, meta)
>>    end
>> end
>>
>> val1 = Box("a")
>> val2 = val1
>> =val2:get()
>> val1:set("b")
>> =val2:get()
>>
>>
> Yeah. that's a way. but I need to change my model and
>widget
> implementation...
>
> I came from the TCL world, and there is a tracevar can
>do this, so I'm
> wondering if Lua has similar functionality..


Dave Dodge | 1 Dec 2006 16:37
Favicon

Re: Table Garbage Collection

On Thu, Nov 23, 2006 at 05:01:20PM +0000, David Given wrote:
> Whoops. You're right; I'd misread the documentation and conflated IA64 pages
> with 'huge pages', which is a Linux kernel feature to save TLB space;

Just a data point: on my Linux/IA-64 system, normal page size is 16K
and hugepage size is 256M.  Those are the defaults that SGI's kernel
provides.

Hugepages can be a hugepain to deal with, though there is a relatively
new libhugetlbfs which supposedly simplifies things and allows
malloc() to use them.

                                                  -Dave Dodge

manel | 1 Dec 2006 17:58
Picon

Re: accented characters in field names (once more)


On Sun, 26 Nov 2006, Luiz Henrique de Figueiredo wrote:

>> The key is the division of the problem in two calls.
>
> Yes, you could save the first script as setlocale.lua and then do
> 	lua -lsetlocale myscript.lua
>
> --lhf
>

Hello,

It does not work for me. We have to break the program in two files (in
Linux; in Windows I have not tried yet, but I wait more troubles |-)
and one loads the other.

This is a problem, because we want to prepare an exe from the lua code
that other people could execute without the Lua interpreter in their
computers.

Manel


Gmane