lua-users home
lua-l archive

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

>>Basically, Lua-swig generates 'userdata' for constants in order to
avoid them to
be overwritten as if they were simple Lua global variables.
On the other hand, this trick also apply to global variables and permits
to uses
'C' global variables (as long as they are of some basic type, char, int,
float...) as Lua global variables: writing to them modify the actual C
(as intented).
Hope it makes this "inefficient" choice a little bit clearer.

I'm not an expert on tag methods. From what I remember you can only
settagmethods on tables and userdata. Hence your decision? I just
wondered if there was a solution which didnt require the allocs (ie.
alloc memory and create a userdata object for every readonly constant).
Our code is particularly sensitive to this as we want to avoid

readonlytag = newtag()

        function (obj,t)
          return t.value
        end )

        function (x)
          error("Cant do that")
        end )

-- this bit could be generated by the binding
my_pi = { value=3.1415927 }

print (my_pi)  -- will print value
my_pi = 1  -- throws an error

You could then have another tag method for readwrite which wrote through
back to the C code instead of giving an error.