Author Topic: String Size  (Read 1974 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
String Size
« on: April 30, 2015, 06:15:47 PM »
I'm having an issue with scriba_LoadProgramString when I use escape characters in the SB code. (\n for example) I'm doing a strlen(sbpgm) in the ext. module but I think the API is expecting the unescaped text length like when it gets the script from the file.

Any ideas how I might resolve this at the C level inside the ext. module?

« Last Edit: April 30, 2015, 06:17:21 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2747
    • ScriptBasic Open Source Project
Re: String Size - Resolved
« Reply #1 on: May 01, 2015, 07:44:18 PM »
I resolved this self inflected issue by escaping the escape character in the source string.

Code: Script BASIC
  1. sb_code = """
  2. FUNCTION prtvars(a, b, c)
  3.  PRINT a,"\\n"
  4.  PRINT FORMAT("%g", b),"\\n"
  5.  PRINT c,"\\n"
  6.  prtvars = "Too Cool!"
  7. END FUNCTION
  8. """
  9.  
  10. sb = SB_New()
  11. SB_Configure sb, "/etc/scriba/basic.conf"
  12. SB_Loadstr sb, sb_code
  13. SB_NoRun sb
  14. fnsn = SB_Address(sb, "main::prtvars")
  15. PRINT SB_CallSubArgs(sb, fnsn, 123, 1.23, "One,Two,Three"),"\n"
  16. SB_Destroy sb
  17.  


jrs@laptop:~/sb/sb22/sbt$ time scriba testicall.sb
123
1.23
One,Two,Three
Too Cool!

real   0m0.004s
user   0m0.005s
sys   0m0.000s
jrs@laptop:~/sb/sb22/sbt$