PDA

View Full Version : Run LScript-A from LScript-B... Possible?



BlueApple
07-23-2008, 10:17 AM
We have a set of LScrtipts that we commonly use in sequence, and we were thinking about bundling them somehow. I could crack them open and integrate all of them into a single script, but someone suggested that we use a new script to call up the individual scripts and execute them. So, two questions:

1.
Can an LScript call up another script and execute it? I know file object agents can be used to read the file data but I am unsure as to how the data would be executed as code.

2.
Is there any danger to using this method?

adamredwoods
07-23-2008, 11:40 AM
You set up your script as a function.


foo: var
{
//foo is your function
...
}

ANd call from your generic:

@insert(file)

generic
{
foo(var);
}

You can use that insert command to keep your code in a separate file.

No danger to using this method.

BlueApple
07-23-2008, 12:04 PM
Adam,
Thanks for the assistance.

art
07-23-2008, 12:20 PM
Adam, did you ever encounter any strange issues with @insert in lscript? I had one script that used 10 or so inserted files and on some occasions I was getting strange syntax errors (inside inserted files) where there were no errors. The exactly same code/functions worked fine when all placed in a single (big) file. Sometimes adding few lines here and there would make the problems come back/go away. It is difficult to explain, but it was very annoying. I wonder if anyone else had similiar problems. Ultimately, because of this I gave up on @insert and switched to editor that allows for code folding.

BlueApple
07-23-2008, 12:36 PM
I am getting a malformed pragma directive error with the below.


@insert("ModelerTest.ls")//returns malformed pragma directive
@insert(ModelerTest2.ls)//returns malformed pragma directive

Any thoughts?

BlueApple
07-23-2008, 03:19 PM
Figured out the syntax for @insert, but am having trouble calling up a specific function. Below are the scripts being tested.


//THIS IS RunModelerTest.ls:
@version 2.2
@warnings
@script modeler
@insert ModelerTest1.ls

main{
fTesty1();
}




//THIS IS ModelerTest.ls
@version 2.2
@warnings
@script modeler

main{
}

fTesty1{
info(555);
}

When I run RunModelerTest.ls nothing appears to happen. Now, if I put anything inside of the main function in ModelerTest.ls and then run RunModelerTest.ls, all of the code inside of the main function executes.

I have also tried defining the function fTesty1 inside of the main function in ModelerTest.ls, but that just returns an error.

Is there a way to call up a specific function, or does the entire body of the main function simply execute when @insert is used?

Also, I tried listing multiple external .ls files at the top...

//@version 2.2
@insert ModelerTest1.ls
@insert ModelerTest2.ls

...but only the first script listed seems to execute.

Any advice? BTW, I am using LW8.5.

Lightwolf
07-23-2008, 03:23 PM
Any advice?
Just a hunch.

Can you try this?:


//THIS IS ModelerTest.ls

fTesty1{
info(555);
}


After all, an include should just work like a complete copy/paste. In your case that would mean two main{} in your script.

Cheers,
Mike

BlueApple
07-23-2008, 03:31 PM
Mike,
Well done, that works like a charm. Gracias.
-Adam

Lightwolf
07-23-2008, 03:32 PM
Mike,
Well done, that works like a charm. Gracias.
-Adam
Wow, that was a longshot, good to know it worked. :D

Cheers,
Mike

adamredwoods
07-23-2008, 05:05 PM
Adam, did you ever encounter any strange issues with @insert in lscript? I had one script that used 10 or so inserted files and on some occasions I was getting strange syntax errors (inside inserted files) where there were no errors. The exactly same code/functions worked fine when all placed in a single (big) file. Sometimes adding few lines here and there would make the problems come back/go away. It is difficult to explain, but it was very annoying. I wonder if anyone else had similiar problems. Ultimately, because of this I gave up on @insert and switched to editor that allows for code folding.

I don't think I've used that many inserts. FogBug it if you can reproduce it.

faulknermano
07-23-2008, 08:29 PM
did you ever encounter any strange issues with @insert in lscript?

i have.

and yes, it's rather annoying. although i'm going to give some 'tips', there is nothing scientific about them; it confuses me just the same, but i thought that it may contribute to getting rid of those @insert-related errors.

*make sure there are empty lines after every @insert'd file. meaning enter a newline at the bottom of the files.

*use absolute paths. it works more reliably.

*there seems to be a some sort of limit to the number of @insert'd files. for me, that number is 6. your mileage might vary.

*when i was coding i realised that when the errors start appearing, LW goes into a unstable state. but once i restart lw, it disappears. so, my conclusion is that as long as you inserting files in, you would need to restart LW frequently until your *whole* script is actually working. because of this, i manually in-lined all my inserted files at the bottom of the script and temporarily got rid of the @insert directives. after sorting that build i got rid of the in-line'd code and put the @insert's back on.

currently, the script is doing fine. but as i modify the code further it would pop up now and then. i wont in-line any more, but i do have to restart LW and make sure the code is fixed.

art
07-23-2008, 09:45 PM
Good to know that I am not the only one who had this problem :) I was definetely over 6 interted files. Anyway, I am not sure if it is easy to reliably replicate this for FogBugz. I'll try. It would be nice to get this fixed, but it is not a priority, not for me at least.

Thanks for the tips faulknermano. I'll try them next time. I never realized that restarting LW may temporarily fix the errors.

evenflcw
07-24-2008, 07:06 AM
I just did this to run my own generic scripts in sequence. You should be able to do the same in Modeler (although there you call different functions, don't remember what they are, one for commandsequence and another for meshdataedit plugins/scripts).



generic
{
item = Scene().firstSelect();

SelectItem( item.id );
CommandInput("Generic_ef_MakeBonesFromMesh");
CommandInput("Generic_ef_SetTargetToNext");
CommandInput("Generic_ef_ApplyPointInfoNode");
}


Thanks for the @insert() pragma suggestion. I had no idea about that one.

jeremyhardin
08-07-2008, 05:55 AM
Passport is broken up into 5 script files. when I went to 6 for organization's sake I got errors, so I had to keep at 5.

2 more things about @insert that I haven't seen said are...
The inserted scripts get brought into the one compile if you compile it as lsc.
The inserted scripts should only contain functions to be referenced manually. No 'main', 'generic', 'load',' save', 'create', 'destroy' etc., should be in those unless it's the only one in all the scripts you're working with. Function names have to be unique across all the scripts.

faulknermano
08-07-2008, 08:49 AM
in addition to jezza's comments, i also found that if you intend to use global variables declared in the main script, you need to declare them also in the @insert'd script (as global variables).

evenflcw
08-18-2008, 06:16 AM
It seems to me @insert never really looks in the running scripts own folder at all. And this is the reason absolute paths seem more reliable. If you don't supply a absolute path it will popup the file requester do you can provide the full path when you install the script and run it for the first time.

Also calling debug() from within an inserted file crashes LW.



Does anyone know of a constant/define which contains the running scripts folder? I parsed the lwext.cfg for now.

faulknermano
08-18-2008, 06:21 AM
SCRIPTID is the constant you're looking for i believe. but i'm not sure if you can string up a constant to be used for pragmas like @insert. i think i tried this without success. :(

faulknermano
08-18-2008, 06:25 AM
and also, based on the new 9.5 SDK docs, the '@' symbol tries to look for the @insert'd file in the same directory as the running script. BUT, it does not seem to allow for additional folders. meaning you can do this:



@insert "@insertfile.ls"


but you *cannot* do this:



@insert "@\\mySubfolder\\insertfile.ls"


at least i couldnt. anyone else have luck with this?

evenflcw
08-18-2008, 07:30 AM
Thanks for SCRIPTID!

I'm had no luck with the @insert "@insertfile.ls" at all. I still have to go through the filerequestor and pick the file manually and now the default filename in the requester is @insertfile.ls (with the 'at'), so it doesn't seem to parse the @ at all for me.

Even if it did work it was a strange solution compared to just making the insert pragma search the running folder before looking elsewhere. This "@..." thing is just odd.

*sigh*

dpont
08-18-2008, 09:02 AM
@insert "@\\mySubfolder\\insertfile.ls"


at least i couldnt. anyone else have luck with this?

@insert "//mySubfolder//insertfile.ls"

works here,
was in Modeler with a simple UDF in insertfile.ls
called from the main() in my lscript.

Denis.

faulknermano
09-22-2008, 09:19 PM
i discovered another thing: there is usually a limit of insert'd files. somewhere around 5-6, and then lscript becomes 'unstable.' but there's a trick: cascade your insert files into other insert files. for example, i have 'register' insert files that are called like this:



@insert "C:\\GenericIncludes.ls"
@insert "C:\\PluginIncludes.ls"
...


and in the GenericIncludes.ls



@insert "C:\\FileIO.ls"
@insert "C:\\Strings.ls"
@insert "C:\\Math.ls"



and on and on it goes.


btw: denis, thanks for your @insert test. :)

sami
12-15-2012, 04:04 AM
i discovered another thing: there is usually a limit of insert'd files. somewhere around 5-6, and then lscript becomes 'unstable.' but there's a trick: cascade your insert files into other insert files. for example, i have 'register' insert files that are called like this:
...

Sorry to revive this old thread. I am trying to insert maybe 4-5 files (and I'd like to do more to keep my serialized graphics & datastructures as separate libraries) but I keep getting "error in 'sequence' pragma" but obviously I am using @sequence 's inside my inserted files. Anyone have any idea about this? If they are in the main file all works fine - I've tried with and without the @version at the top of the inserted files and with all files @insert'ed into the main file or nesting them for dependencies.

My only other option is to keep the @inserts down to like 2 which doesn't seem to crap out (even with sequences in the main and one of the @inserts) and just use Comment folding to keep the "library" out of the way -- that doesn't help with reuse of code so much though... Any more thoughts on this old problem and why I'm getting the pragma error?

thanks!

evenflcw
12-15-2012, 07:24 AM
I've ended up just ditching sequences, using constants until they failed aswell, to finally resort to global variables. Use of any type of pragma in inserted files just seems to be cause for odd crashes. You will be fighting with the inserts enough as it is, so just pick the simplest solution when you know there is one.

I'd be interested to hear any insights from Faulknermano or other aswell though.

faulknermano
12-21-2012, 09:46 AM
Well, my first thought is that if the pragma is crapping out it may be because the sequence structure is being used outside the script that initialised it, which is ironically the reason for having the library in the first place. I'm only guessing this is the case because I know for a fact that that I can't use global variables in a script at doesn't declare it itself even though it has been declared and used in another.

I agree with Dan's method. I'd simplify it by not using sequence pragmas, but perhaps using arrays and constants (define pragmas), or better, arrays and very recognisable variable names for integers (ex: _MOTOROLA_ = 1;) However I realise that that doesn't solve the problem of encapsulating a library neatly. But it is better than sequence; your library can initialise the integer value for the variable, and the using script can just re-declare the variable if it needs to be used.