Author Topic: SB & C  (Read 15634 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
SB & C
« on: April 15, 2010, 02:21:26 AM »
I have been playing around with the CINT C interpreter and thought I would give it a try within ScriptBasic.

Code: Text
  1. PRINT "Hello "
  2. x = EXECUTE("cint world.c",-1,p)
  3.  

Code: Text
  1. #include <stdio.h>
  2. main() {
  3.   printf("World");
  4.   }
  5.  

Output:

C:\scriptbasic\test>hello
Hello World
C:\scriptbasic\test>

Q. Can you pass variables to your C program and get the results of the C program returned back to the ScriptBasic program in a string?

A.
If the number of variables you want to pass are many, build the C program dynamically in SB and write it to a file with the embedded SB variable values as C constants. (the SB constants could be an #include file as well) If you only need to pass a couple values, then add them to the EXECUTE(cint pgm arg) and extract them from the C program's command line argument when it runs.

To return results back to SB, you need to redirect the output to a file and open it in SB after the C program runs and GET the results. If your going to use redirection or piping, you need to include the CMD processor in your EXECUTE statement.

Code: [Select]
x = EXECUTE("cmd /C \"cint your_pgm.c > results.out\"", -1, pval)
« Last Edit: April 16, 2010, 01:47:53 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: SB & C
« Reply #1 on: April 16, 2010, 11:39:24 AM »
It looks like embedding CINT into ScriptBasic may not be all that hard to do. Having a C interpreter to compliment ScriptBasic syntax should make SB more attractive as a prototyping and learning tool. The goal with ScriptBasic is to provide a BASIC scripting tool that gets the job done quickly with as little code as possible and runs on everything. ScriptBasic is extensible, embeddable and can adapt to most of your one off programming needs.

CINT Users Reference

CINT API
« Last Edit: April 16, 2010, 12:09:12 PM by support »