We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LDCall Extension
#1
How Can We Get The Errors in SB Code When Using LDCall.Compile ??
ZS
Reply
#2
All this does is call the Small Basic compiler, there are no errors using this.  Check your sb file compiles first before using this method.
Reply
#3
I Mean If There Is An Error In SB File How Will We Get It Through The Method.
ZS
Reply
#4
ZS,
Sorry, you cannot get details of compilation errors from these methods.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#5
Please tell me if I can read somewhere about how to use the "LDCall.CallInclude()" method correctly?
How to create an include file correctly?
And how to correctly use the variables in these two files? Does the include file see the variables that are in the program that calls it? And does the calling program see the variables created in the include file?

Thank you.
Reply
#6
Hi, There is no additional documentation, see the intellisense documentaion for LDCall.Include and LDCall.CallInclude.

To be totally honest I can't remember exactly and would have to do some tests to be sure.  First have a go, and a few tests should answer the questions.

If you have questions after your tests then I'm happy to help with these and show the actual logic used, which is also available by looking at LitDev.dll using dotPeek for example.

This kind of detective work is a big part of working out how stuff works - it's unusual to find an exact answer to every specific question.
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#7
(05-19-2024, 05:07 PM)litdev Wrote: ...
This kind of detective work is a big part of working out how stuff works - it's unusual to find an exact answer to every specific question.

I completely agree with you.  Wink
But, my parents and my life taught me to ask people first. If I hadn’t asked, I would have given rise to jokes at my expense: “You’re an eccentric. What, you couldn’t ask, or what?”

Thanks a lot. All the best to you.
Reply
#8
It's a bit trick to work out the logic, so here it is:

There are probably a limited number of situations where CallInclude makes more sense than just copying the subroutine into your code.

When the include subroutine is called it knows nothing about the rest of the include program code, as if we just copied the subroutine into the main program.

First create and compile the include program with a subroutine we want to use.

There is a 3 step process when CallInclude is run, assuming all files exist compiled etc.

1] All calling program variable values (that have the same name in both programs) are copied to the include program.
2] The include subroutine is called.
3] All include variables (some may now be modified by the subroutine) are copied back to the main program.

Consider include program (Include.sb):

Code:
x = 1
y = 1
z = 1
MySub()
TextWindow.WriteLine(z)
Sub MySub
  z = x+x+y
EndSub


And calling program:

Code:
x = 2
z = 2
inc = LDCall.Include(Program.Directory+"/Include.exe")
TextWindow.WriteLine(inc)
result = LDCall.CallInclude(inc,"MySub")
TextWindow.WriteLine(result)
TextWindow.WriteLine("x="+x)
TextWindow.WriteLine("z="+z)


Step 1] In included code : x set to 2, z set to 2, y is unset (default 0) - remember the CallInclude only looks at the subroutine MySub, it knows nothing about previous code that sets y = 1 for example.
Step 2] MySub sets z = 2+2+0 = 4
Step 3] In main program : x set to 2, z set to 4

Resulting output:

Include1
SUCCESS
x=2
z=4
Press any key to continue...
[-] The following 2 users Like litdev's post:
  • AbsoluteBeginner, z-s
Reply
#9
Oho!..  Huh
It looks like I didn't "ask first" for nothing.

I was aware of the variable visibility issue. But, I wouldn't have guessed about "passing values" of variables that have the same names.
Thanks a lot.

I wanted to use an include file so as not to clutter the Server code with Snake AI code.
Well, in general, it’s useful and interesting to learn something new.

Thank you.
Reply
#10
You could see examples of ldcall in litdev samples
ZS
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)