Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code in variables or resources
#1
I've always had a confusion: between the following two types of code, which one is relatively safer?
My thought is: script c1.
 
Reason:
The code of script c1 is stored in a variable, while the code of script c2 is stored in a resource.
Can it be directly viewed using a resource viewer tool?
 
Is the above understanding correct?

Macro c1
Code:
Copy      Help
out

str code=
;public class Class1
;{
;;;;;public static string StaticFunc(string s)
;;;;;{
;;;;;;;;;return s;
;;;;;}
;}
str R=CsFunc(code "hello")
out R

Macro c2
Code:
Copy      Help
out

str R=CsFunc("" "hello")
out R

#ret
public class Class1
{
;;;;public static string StaticFunc(string s)
;;;;{
;;;;;;;;return s;
;;;;}
}
#2
In c1, visible is only the string (C# code). In c2, visible is whole macro.
#3
Or the same, I don't remember exactly, need to read docs.
CsFunc contains `#exe addtextof "<script>"`. Probably it means it adds even c1 text to exe resources.
#4
Thanks for your help.
Quote:#exe addtextof "<script>"
I don’t quite understand what this line of code does.

In the function `getSubCode` below, I used this line.

1. When I run the macro `getSubCode_T` in QM, it works successfully!
2. But when I compile `getSubCode_T` into an EXE file and run it, it fails.

I use the `getSubCode` function in many macros, and I’ve tried various solutions but haven’t been able to resolve the issue.

Can you help me? In any case, thank you very much!

Function getSubCode_T
 
Code:
Copy      Help
out

getSubCode("a" _s); out _s
getSubCode("b" _s); out _s

#sub a
A

#sub b
B

Function getSubCode
Code:
Copy      Help
function $subName str&code ;;Get text from the sub-function

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

int iid=+getopt(itemid 1)
code.getmacro(iid)

str m="^#sub sn.*[]"; m.findreplace("sn" subName)
str s; int l i=findrx(code m 0 8 s) ;;
if i!=-1
,s.trim
,;out s
,foreach _s code
,,_s.trim
,,if(_s=s) break
,,l+1
else
,end F"#sub {subName} Not found!"
for _i l+1 numlines(code)
,str s_.getl(code _i)
,if(s_.beg("#sub") or s_.beg(" BEGIN PROJECT"))
,,break
,else
,,str cf.addline(s_ -1)
cf.rtrim;
if(empty(cf)) end F"#sub {subName} content is empty!"

code=cf
#5
The following code, after being compiled into an .exe, executes successfully. It seems that the text below #ret has been successfully embedded into the .exe.

What I need, however, is to retrieve the text within a specific sub-function (#sub xxx) and embed that into the generated .exe. How can this be achieved?

Macro CsFunc_T2
Code:
Copy      Help
out

str R=CsFunc("" "hello")
out R

#ret
public class Class1
{
;;;;public static string StaticFunc(string s)
;;;;{
;;;;;;;;return s;
;;;;}
}
#6
I looked in #exe docs and it says that the caller's text is added only if the first argument is "".
#7
Thanks for the reminder.

"embed the code text below #ret into the .exe, and extract that code text from the .exe when the function is called."

I tried using ChatGPT to analyze how this works, but had no luck.

If I can solve this problem, it would also help me resolve many of my previous related issues.


Forum Jump:


Users browsing this thread: 1 Guest(s)