lua-users home
lua-l archive

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


You seem to form very simple questions in a very complicated fashion.

If I understand your problem correctly there is no need for the script to
know the name of the namespace.  For instance...

-- enemy.lua

return {
 	PositionX = 0.0,
 	PositionY = 0.0,
 	PositionZ = 0.0,

	new = function()
		return {}
	end,

	Initialise = function (self, x,y,z)
		self.PositionX,self.PositionY,self.PositionZ = x,y,z
	end,

	Update = function (self, time)
   		self.PositionX = (self.PositionX + 1.0) * time
	end
}

-- Alternatively...
Use your example code by end the script with...

return enemy

-------

Now if scripts are allowed to access the "namespaces" of other scripts then
you do have a problem to solve as you have to come up with some consistent
way to name these "namespaces", and yes it is likely that using the name of
the script file makes sense (it just depends on your usage context).

Further if you wish to protect the scripts from each other (or anything else
from the scripts) then you probably want to set the index/newindex
metamethods for the globals table.  Then if you really wish to go to lengths
to hide from the users the fact that you are "namespace wrapping" their
scripts you can just redirect accesses to globals to the "namespace" created
for the currently running script (again if scripts can call into other
scripts then you have additional issues).


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Paul Tankard
Sent: Saturday, September 20, 2003 5:57 AM
To: Lua list
Subject: RE: Building a system using Lua - question following the
"MyBrainHurts" mail.



personally for ingame usage I don't think using multiple VM's is necessary
as Michael said, use namespaces.
so the way I will be implementing Lua for now ;) is to have one VM and have
each script use a namespace (read table)
and my application will setup any entities using the correct namespace.. the
only downfall of this is knowing what the namespace is called, I mean, if
you enable a user to create a random script which follows some basic rules,
like the table should contain certain functions, you still have the problem
of the host machine knowing what namespace is used, this isn't a problem if
your dealing with everything via script because you can amend you script
easily, but when your assigning script to entities via some form of editor
this becomes a problem.. unless you have another rule stating the namespace
should match the script name.. so.. (untested script follows, just example
;)

--enemy.lua

enemy= {
 	PositionX = 0.0,
 	PositionY = 0.0,
 	PositionZ = 0.0
}

function enemy:new()
	return {}
end

function enemy:Initialise(x,y,z)
	self.PositionX,self.PositionY,self.PositionZ = x,y,z
end

function enemy:Update(time)
   self.PositionX = (self.PositionX + 1.0) * time
end

then you can assume from the filename what the namespace is.. this is very
ugly and prone to errors, but until I understand a little more of the
workings and features of Lua I'm stuck in doing it this way for the time
being.

Regards,

PT



[Big snip]
>------------------------------------------------------------------------
>----------------
>A multiple Virtual Machine architecture :

<<attachment: winmail.dat>>