Page 1 of 1

Why are goto and dofile, among other lua commands, disabled?

Posted: Fri Oct 02, 2015 10:24 pm
by fdrown2226
The lua programming language includes the commands 'dofile' and 'goto' among others, and I would like to utilize them with my mods. There is a wonderful debugging utility I would love to use, however, because you don't allow dofile, I can't. I am able, using functions, to work around the goto to a certain extent, however, there is no workaround for the dofile command. :cry:

Re: Why are goto and dofile, among other lua commands, disab

Posted: Fri Oct 02, 2015 11:36 pm
by minmay
In Grimrock 1 you can spawn a script entity and set its source using the SetSource() method. You don't really get dofile functionality but you can get fairly close. Take a look at jkos' LoG Framework.

In Grimrock 2, you can imitate dofile (or dostring) like this:
1. Add this object definition:

Code: Select all

defineObject{
	name = "file_doer",
	components = {
		{
			class = "ScriptController",
			name = "controller",
			onInit = function(self)
				self.go.script:loadFile(fileDoerControl.script.filename)
			end,
		},
		{
			class = "Script",
		},
	},
	placement = "floor",
}
2. Add a script_entity called fileDoerControl with this function:

Code: Select all

function dofile(scriptName,fName)
	filename = fName
	spawn("file_doer",self.go.level,self.go.x,self.go.y,self.go.facing,self.go.elevation,scriptName)
end
Now you can call fileDoerControl.script.dofile("cows","mod_assets/scripts/cows.lua") to create an object named "cows" with a ScriptComponent named "script" that immediately executes cows.lua. It will support connectors too because it has a ScriptControllerComponent, though of course these connectors will have to be added dynamically.
If you want dostring instead then just replace the loadFile() call with setSource().



As for 'goto', why the hell do you want goto in the first place...

As for other lua features, security.

Re: Why are goto and dofile, among other lua commands, disab

Posted: Sat Oct 03, 2015 8:20 am
by petri
Lua 5.1 which Grimrock uses has no goto statement. Goto appeared in Lua 5.2.

Dofile does not work with published mods (all the files are packed in one big file). But you can use "import" in asset definition scripts.