Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getRetCode in exe
#1
The code of macro T1 can execute successfully in both qm and exe,

but the code of macro T2 only executes successfully under qm and returns empty in exe.

The purpose of creating the `gr` function is just to be more concise.

Macro T1
 
Code:
Copy      Help
sub.gr(_s); mes _s ;;OK

#sub gr
function str&code
getRetCode("" code)

#ret
hello

Macro T2
 
Code:
Copy      Help
gr(_s); mes _s ;;qm: OK    exe: NO

#ret
hello

Function gr
 
Code:
Copy      Help
function str&code
getRetCode("" code 2)

Function getRetCode
Code:
Copy      Help
function $macro str&code [context] 

#exe addtextof "<script>"
#opt nowarnings 1
opt noerrorshere 1

if(!macro or (macro>=0x10000 and !macro[0]))
,int iid=+getopt(itemid -iif(context context 2))
else
,iid=qmitem(macro 1); if(!iid) end ERR_MACRO
code.getmacro(iid)

int n i=findrx(code "^#ret\b.*[]" 0 8 _i)
if i>=0 
,i+_i-2
,code[i]=0; n=numlines(code)-1; code[i]=13
,code.replace(_s.all(n 2 10) 0 i) 
else if 0=findrx(code "^[ ;]*[/\\](?![/\*]).*[]" 0 0 _i)
,code.remove(0 _i-2) 

code.trim
#2
#exe addtextof "<script>" add text of the caller to exe, if it calls with the first argument "". I found it in #exe documentation. I could not find a way to add text of the script in a similar way. In script use #exe addtextof "T2".


Forum Jump:


Users browsing this thread: 1 Guest(s)