lucv | 1 Dec 16:27 1998
Picon

Saving and loading the lua state

Hello all,

I need to save and load the lua state to and from disk. Any bright ideas
on how to go about this ? I'm using the lua_newstate C function from the
documentation to get a copy of the state, and I which to save this to
disk.

All help appreciated,

--Luc

David Jeske | 1 Dec 18:58 1998
Picon

equivilant of 'index' tag method for globals?

I feel like I should be able to do this, but I can't see how to do it
with the existing fallbacks. I want to have a tag method called when a
global variable dosn't exist.

I want to do this because I want to separate 'enum' types from the
current global table, but I want them to have global scope. In the
end, it will look something like this:

enums = { 
    dog_names = {
          ROVER = 1,
          SPOT  = 2,
          FIDO = 3
    },
    car_makes = {
          HONDA = 1,
          FORD = 2,
          NISSAN = 3
    }
}

function e_type(varname) 
  local enum_value
  local enum_name

  enum_value,enum_name = find_enum(varname);
  return enum_name
end

print(ROVER) -- 1
(Continue reading)

Roberto Ierusalimschy | 1 Dec 18:20 1998
Picon
Picon

Re: equivilant of 'index' tag method for globals?


  settagmethod(tag(nil), "getglobal", <your function>)

<your function> will be called with the name of the global variable and
its original value (nil in this case). (I suppose it is "find_enum" in your
case).

-- Roberto

Steve Dekorte | 1 Dec 20:24 1998
Picon

Re: equivilant of 'index' tag method for globals?

On Tue, 1 Dec 1998, David Jeske wrote:

> I feel like I should be able to do this, but I can't see how to do it
> with the existing fallbacks. I want to have a tag method called when a
> global variable dosn't exist.
> 
> I want to do this because I want to separate 'enum' types from the
> current global table, but I want them to have global scope. In the
> end, it will look something like this:

I think this will work:

settagmethod(tag(nil), "getglobal",
 function (varname)
    local value = gettable(rawgetglobal("enums"), varname)
    if ( value ~= nil ) then return value end
    return rawgetglobal(varname)
 end )

I use this sort of thing to move Lua's primatives out of globals and 
into a organized namespace.

---
Steve Dekorte 

Steve Dekorte | 1 Dec 20:28 1998
Picon

Re: equivilant of 'index' tag method for globals?


Oops, I forgot that I don't need to try to look up the global, since this
tag method only gets called when that global is nil. So this is all 
that's needed:

settagmethod(tag(nil), "getglobal",
  function (varname) 
    return rawgettable( rawgetglobal(enms), varname)
  end )

---
Steve Dekorte 

David Jeske | 1 Dec 20:59 1998
Picon

Re: equivilant of 'index' tag method for globals?

On Tue, Dec 01, 1998 at 04:21:11PM -0200, Roberto Ierusalimschy wrote:
>   settagmethod(tag(nil), "getglobal", <your function>)
> 
> <your function> will be called with the name of the global variable and
> its original value (nil in this case). (I suppose it is "find_enum" in your
> case).

Thanks, that worked great. I wasn't understanding that it was actually
calling the 'getglobal' tag method on the "nil" which is returned
because the variable isn't there. I'm all straightened out now.

--

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske <at> chat.net

David Jeske | 1 Dec 21:28 1998
Picon

non-empty false...

I'm trying to put together a non-empty false value, and I can't figure
out a way to do it. It seems to me that in order to do this I would
need a tag method which is used for boolean comparison (as opposed to
assignment). That way I could do:

FALSE = {}
local a_tag = newtag();
settag(FALSE,a_tag)

settagmethod(a_tag,"bool",
    function (a_table) 
       return nil;               
    end
   );

Do any of you know an existing method for getting this kind of behavior?

=====

I have three reasons for wanting to do this:

1) My first motivation for this is that in proto-style "parent"
inheritence schemes, any values which are "nil" are not-present, which
means that accessing them requires a search of the entire inheritence
tree, just to not find the nil value. 

2) My second motivation is that Lua "nil" false values confuse the nice
proto-override style inheritence behavior. That is, if I have:

  super_obj = {
(Continue reading)

Steve Dekorte | 1 Dec 22:30 1998
Picon

Re: non-empty false...

On Tue, 1 Dec 1998, David Jeske wrote:

> I'm trying to put together a non-empty false value, and I can't figure
> out a way to do it. It seems to me that in order to do this I would
> need a tag method which is used for boolean comparison (as opposed to
> assignment). That way I could do:
> 
> Do any of you know an existing method for getting this kind of behavior?

You could have global true and false objects and use an "isEqual_" method
in place of "==".

true = {
    isEqual_ = function (self, o) 
	if ( self == o ) then return 1 end
	return 0
}

false = clone(true)

> I have three reasons for wanting to do this:
> 
> 1) My first motivation for this is that in proto-style "parent"
> inheritence schemes, any values which are "nil" are not-present, which
> means that accessing them requires a search of the entire inheritence
> tree, just to not find the nil value. 

how about using "Nil" instead of nil and making Nil = 0?
(Just use 0 instead off nil for false boolean values)

(Continue reading)

David Jeske | 1 Dec 23:26 1998
Picon

Re: non-empty false...

On Tue, Dec 01, 1998 at 07:31:51PM -0200, Steve Dekorte wrote:
> > I'm trying to put together a non-empty false value, and I can't figure
> > out a way to do it. It seems to me that in order to do this I would
> > need a tag method which is used for boolean comparison (as opposed to
> > assignment). That way I could do:
> > 
> > Do any of you know an existing method for getting this kind of behavior?

> You could have global true and false objects and use an "isEqual_" method
> in place of "==".

> how about using "Nil" instead of nil and making Nil = 0?
> (Just use 0 instead off nil for false boolean values)

Neither of these solutions work well with standard binary
operations. Plus, I don't want to have to bloat the syntax with object
calls everywhere for simple operation. What you're suggesting would
turn this:

  if (a_value or another_value) then

into this:

  if (a_value:or(another_value):isEqual(TRUE)) then

No thanks... I'd rather put a proper boolean type into Lua than
confuse up the syntax. I was just hoping for a simple way to do it
within the Lua runtime meta-mechanisms.

--

-- 
(Continue reading)

Steve Dekorte | 1 Dec 23:52 1998
Picon

Re: non-empty false...

On Tue, 1 Dec 1998, David Jeske wrote:

> No thanks... I'd rather put a proper boolean type into Lua than
> confuse up the syntax. I was just hoping for a simple way to do it
> within the Lua runtime meta-mechanisms.

I also suggested using 0 instead of nil.
What about that? 

---
Steve Dekorte 


Gmane