messages within messages

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

messages within messages

Steve Dekorte-2
I seem to have a problem doing:

   object:methodA(otherObject:methodB())

although it works fine if I do:

   local temp = otherObject:methodB()
   object:methodA(temp)

Is this a known limitation in Lua, a bug, or am I doing
something wrong?

Steve

Reply | Threaded
Open this post in threaded view
|

Re: messages within messages

Steve Dekorte-2
>I seem to have a problem doing:
>
>object:methodA(otherObject:methodB())
>
>although it works fine if I do:
>
>local temp = otherObject:methodB()
>object:methodA(temp)
>
>Is this a known limitation in Lua, a bug, or am I doing
>something wrong?


Oops, I meant to say:

   object:methodA():methodB()

doesn't work, but:

   local temp = otherObject:methodB()
   temp:methodA()

Does.

Steve

Reply | Threaded
Open this post in threaded view
|

Re: messages within messages

Roberto Ierusalimschy
> Oops, I meant to say:
>
>   object:methodA():methodB()

The syntax for function calls is   <varexp>:name(<params>), where <varexp> is
a simple name, or <varexp>.name or <varexp>[exp]. Unfortunately, it is not
possible to write a generic expression as the function to be called. We have
tried to change that, but we've always got parsing problems. So, the solution
is to use a local temporary variable, as you did.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: messages within messages

Steve Dekorte-2
>object:methodA():methodB()
>
>The syntax for function calls is   <varexp>:name(<params>), where <varexp> is
>a simple name, or <varexp>.name or <varexp>[exp]. Unfortunately, it is not
>possible to write a generic expression as the function to be called. We have
>tried to change that, but we've always got parsing problems. So, the solution
>is to use a local temporary variable, as you did.

Have you considered replacing Yacc with a custom parser?

Steve

Reply | Threaded
Open this post in threaded view
|

Re: messages within messages

Roberto Ierusalimschy
> Have you considered replacing Yacc with a custom parser?
Yes, but I don4t think it would help. Custom parsers are usually
top-down, and so they are weaker than LALR parsers (if they are LL(1)),
or much more tricky and error-prone, if you handle cases one by one.

  This thing with restricted syntax for function calls is the price we
pay for not having semi-collons ending al statetments. Because of that,
the begining of statetments must be very clear. As a simple example:

i = a+b
(f(x)).x(8)  -- generic expression as a function to be called

would be parsed as:

i = a+b(f(x)).x(8)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Lua source file path from a function

Steve Dekorte-2
If I'm in C and have a lua_Object that is a Lua function,
is there a way to get the path of it's source file?

The debbugger APIs seem to do this for functions on the call stack,
but I need to do it for other functions as well.

Steve

Reply | Threaded
Open this post in threaded view
|

Global access control

Russell Y. Webb
Is there any news as to what (if any) strategy might be adopted 
officailly by Lua to control access to globals?  Having the option of 
requiring global access declarations would make Lua much more robust.

I've already written something like 

$noglobals
z=10
q=45
g=54

function example(x)
local w,y
global z,q
   w=x*x
   print(w+x+q)
   print(g)  -- error
end

In standard mode lua just ignores the global list, so this code works in 
either mode ($globals or $noglobals).

Russ

Reply | Threaded
Open this post in threaded view
|

Re: Global access control

David Jeske-2
I like solution, and it's my opinion that it would be a worthwhile
addition to standard Lua. 

On Sun, Dec 28, 1997 at 04:06:56PM -0200, [hidden email] wrote:
> Is there any news as to what (if any) strategy might be adopted 
> officailly by Lua to control access to globals?  Having the option of 
> requiring global access declarations would make Lua much more robust.
> 
> I've already written something like 
> 
> $noglobals
> z=10
> q=45
> g=54
> 
> function example(x)
> local w,y
> global z,q
>    w=x*x
>    print(w+x+q)
>    print(g)  -- error
> end
> 
> In standard mode lua just ignores the global list, so this code works in 
> either mode ($globals or $noglobals).
> 
> Russ
> 

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + [hidden email]

Reply | Threaded
Open this post in threaded view
|

Save/Load Lua Image

Steve Dekorte-2
Here's some psuedo code for reading and writing a Lua image.
I think this addresses the circular reference problem.
It also deals with not having access to function source from within Lua
by assuming that all functions in the image are from seperate externally
existing files.

The one tricky bit is how to get a function definition that's in a file
to get executed and stuck into the write slot value.

(object# = object reference #)

Does it look like this would work to you guys?


----
///////////////////////////////////
// Save Lua image psuedo code
// Writes out all unique tables and functions by
// remembering what's already been written and what has not
///////////////////////////////////
saveLuaImage()
    add globals to unwrittenList
    while ( unwrittenList count > 0 )
        loop through unwrittenList
             writeObject(object)
          endloop
     endwhile
     delete function files that aren't in the writtenList
     print("wrote ".. writtenList count.." objects to image)
end

 writeObject(object)
    if (object is a table ) writeTable(object)
    if (object is a function ) writeFunction(object)
 end

writeTable(aTable)
    remove table# from unwrittenList
    put table# in writtenList
    write "table "..table#.."\n"
    loop through slots
        write slot name
        if (value is string or number ) write raw value
        if (value is an object and is not in writtenList )
            put value object in unwrittenList
        endif
     endloop
end

writeFunction(aFunction)
    remove object# from unwrittenList
    put object# in writtenList
    write "function "..object#..fileNameforFunction(function).."\n"
end

///////////////////////////////////
// Load Lua image psuedo C code
// Reads in all unique tables and functions
// then links all the slots to the right functions and tables
//////////////////////////////////
loadLuaImage()
     open image file
     assume image starts with "globals" table
     create globals table
     call readSlotsForTable(globalsTable)
     put globalsTable in readObjectsArray

     while ( still more in file )
        read object type
        if ( type is table ) readTable() else readFunction() endif
     endwhile

     while ( unlinkedTableList count > 0 )
         loop through unlinkedTableList
             linkSlotsForTable(aTable)
           endloop
     endwhile

     dump globals table slots into globals
end

readFunction()
    read oldObject#, fileName
    if ( oldNewObjectArray[oldObject#] == nil )
       read file with fileName, execute it and get newObject# for function in it
       oldNewObjectArray[oldObject#] = newObject#
    endif
end

readTable()
     read oldObject#
     newObject# = ref of newly created table
     oldNewObjectArray[oldObject#] = newObject#
     if ( tableIsNotDoneLinking(newObject #) )
       add newObject# to unlinkedTableList
     endif
     readSlotsForTable(aTable)
end

readSlotsForTable(aTable)
     loop through slots
          read slot name & value ( or string encoding object#)
          set slot name and value in table
     endloop	
end

linkSlotsForTable(aTable)
     loop through slots
     if ( value is object# and object# in oldNewObjectArray)
               value = oldNewObjectArray[object#]
     endif
     endloop
     if (no unlinked slots left)
         remove aTable from unlinkedTableList
     endif
end

Reply | Threaded
Open this post in threaded view
|

RE: Global access control

Stephen Shaw
In reply to this post by Russell Y. Webb
Sorry to send this to the group, but...
Can someone help me get off this list?  I have tried several times to
send the request to the server with no success...

Thanks in advance,
Srs

[hidden email]

Stephen R. Shaw
LucasArts Entertainment Co. LLC

My views do not necessarily represent those of the company.


	-----Original Message-----
	From:	[hidden email] [SMTP:[hidden email]]
	Sent:	Sunday, December 28, 1997 10:06 AM
	To:	Stephen Shaw
	Subject:	Global access control

	Is there any news as to what (if any) strategy might be adopted 
	officailly by Lua to control access to globals?  Having the
option of 
	requiring global access declarations would make Lua much more
robust.

	I've already written something like 

	$noglobals
	z=10
	q=45
	g=54

	function example(x)
	local w,y
	global z,q
	   w=x*x
	   print(w+x+q)
	   print(g)  -- error
	end

	In standard mode lua just ignores the global list, so this code
works in 
	either mode ($globals or $noglobals).

	Russ

Reply | Threaded
Open this post in threaded view
|

Re: Global access control

Maria das Dores
In reply to this post by Russell Y. Webb
>$noglobals
>z=10
>q=45
>g=54
>
>function example(x)
>local w,y
>global z,q
>   w=x*x
>   print(w+x+q)
>   print(g)  -- error
>end

>From what I could understand from the manual, "print" is also a
global variable, isn't it? How come you can access "print" without
declaring it to be global? That looks weird...

MdD


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply | Threaded
Open this post in threaded view
|

Re: Global access control

Luiz Henrique de Figueiredo
In reply to this post by Russell Y. Webb
>From [hidden email] Mon Dec 29 12:06:10 1997
>
>>$noglobals
>>z=10
>>q=45
>>g=54
>>
>>function example(x)
>>local w,y
>>global z,q
>>   w=x*x
>>   print(w+x+q)
>>   print(g)  -- error
>>end
>
>>From what I could understand from the manual, "print" is also a
>global variable, isn't it? How come you can access "print" without
>declaring it to be global? That looks weird...

excellent point! and one of the reasons why we don't want to change anything
right now. specially since lua already provides tools (metamechanisms!) for
handling this. (of course, such tools are available at run time only.)

we intend to post a longer message about this problem and solution soon.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Global access control

Russell Y. Webb
> >>From what I could understand from the manual, "print" is also a
> >global variable, isn't it? How come you can access "print" without
> >declaring it to be global? That looks weird...
> 
> excellent point! and one of the reasons why we don't want to change anything
> right now. specially since lua already provides tools (metamechanisms!) for
> handling this. (of course, such tools are available at run time only.)

I have thigs setup to allow access to function.  I have a version that
prevents assignment to functions unless they are declared in the global
list. 

It's true that Lua can modify and restrict itself to control global
access, but there are several problems: 

1. Lua can't modify enough tag methods to really fix things (ie. you can't
control plain table access), so have a really hacked up language when
you're done. 

2. Runtime is just too late to detect these errors in a
server environment or other robust system, especially since no overhead is
added to Lua to do it at compile time. 

3. You're adding runtime overhead. 

Lua is a great mixture of power and simplicity.  I can understand 
reluctance to add a language modification at this point (it is a totally 
optional one though).  Anyway, there seems to be some interest in 
global access control, and I don't think having everyone roll there own 
strange solution is a good idea.

If no standard is adopted, I'll probably continue to modify the Lex code 
and make my own version (though keeping up with new Lua releases will be 
a pain).  I'd be glad to post my Lua source files as a optional 
non-standard solution, if that's allowed (is it?).

Russ

Reply | Threaded
Open this post in threaded view
|

Re: Global access control

Fred Bertsch
On Mon, 29 Dec 1997 [hidden email] wrote:

> > excellent point! and one of the reasons why we don't want to change anything
> > right now. specially since lua already provides tools (metamechanisms!) for
> > handling this. (of course, such tools are available at run time only.)
> 
> I have thigs setup to allow access to function.  I have a version that
> prevents assignment to functions unless they are declared in the global
> list. 

This seems like a good solution to me.  It is, of course, fairly rare that
you would want to perform assignment on a function.  However, there are
cases where it can be very useful, and care should be taken to make sure
that these cases aren't any more difficult than before.  

For example, you might want to create a new function with the name given
by a string argument to a function.  While I haven't looked into the
optimal way to do something like this, I would assume it would involve
do_string.  Is it safe to assume that the string evaluated from do_string
is executed from the global scope, and, therefore, can safely assign to
any global, including functions?  Because of the increased differences
between global and local behavior, it becomes more necessary to carefully
define these things.  (Though there are still differences now, so I assume
it's defined somewhere.)

> 1. Lua can't modify enough tag methods to really fix things (ie. you can't
> control plain table access), so have a really hacked up language when
> you're done. 

This does seem to be true.  I haven't come up with a satisfactory answer
to this problem by defining tag methods.

> 2. Runtime is just too late to detect these errors in a
> server environment or other robust system, especially since no overhead is
> added to Lua to do it at compile time. 
>
> 3. You're adding runtime overhead. 

These are worth worrying about.  While it is possible to have a robust
system in some client/server environments with occational messy errors to
deal with, it is far, far better to not have to worry about it.  After
all, the whole point of this discussion is to avoid having to be perfect
all the time.  :)

The runtime overhead of a comprehensive set of tag methods would be
enormous, I suspect.  Simple alternatives such as Russ's $global/$noglobal
syntax are better, simpler, and faster.

> If no standard is adopted, I'll probably continue to modify the Lex code 
> and make my own version (though keeping up with new Lua releases will be 
> a pain).  I'd be glad to post my Lua source files as a optional 
> non-standard solution, if that's allowed (is it?).

At the very least, perhaps you could post the modifications you had to
make to the source code, if not the actual source.  

It looks as though the designers of Lua are thinking seriously about this
issue, and I'm very grateful to them for that!  Thanks!

-Fred

Reply | Threaded
Open this post in threaded view
|

More on Portugese<->English translation

Steve Dekorte-2
In reply to this post by Luiz Henrique de Figueiredo
  http://babelfish.altavista.digital.com/cgi-bin/translate

Just type in the url and select the translation type.

You might try it on: http://www.icad.puc-rio.br/~tomas/iuplua/

Steve Dekorte