You can create aliases to variables from another thread with:
alias(aliasVar, threadObj.ahkgetvar('varName',true))
Can this be done with function as well?
I'd like to avoid using the syntax %funcRef%(params)
AHK_H: how to create an alias to a function from another thread?
Re: AHK_H: how to create an alias to a function from another thread?
More generally, the question is whether it's possible to shorten the expression:
thread.ahkFunction("func_name",params*)
into something like:
func_name(params*)
thread.ahkFunction("func_name",params*)
into something like:
func_name(params*)
Re: AHK_H: how to create an alias to a function from another thread?
You can refer to this script, which requires H2.
Code: Select all
f:=ahkFast("#Persistent`na:=[1,2,3]`ntest(s){`nreturn s`n}")
Sleep, 200
f.set("test","2")
MsgBox % f.a.1 " " f.test " " f.test([1,2,"c"]).3
ahkFast(this:="",code:="",wait:=""){
static dll
if isobject(this)
{
s:="__default_Created(){`nstatic _:=__default_Created(),Thread`n"
. "Thread:=CriticalObject(" (&this) "),Thread.base:={__Call:CriticalObject(Func(`"__default_call`")),__set:CriticalObject(Func(`"__default_set`")),__get:CriticalObject(Func(`"__default_get`"))}`n"
. "}`n__default_get(f,n,p:=`"`"){`nglobal`nTry`nreturn (p?`%n`%[p]:`%n`%)`n}`n"
. "__default_set(f,n,p){`nglobal`nTry`nreturn (`%n`%:=p)`n}`n"
. "__default_call(f,n,p*){`n`nif n:=func(n)`nreturn p.Length()?n.call(p*):n.call()`n}`n" code
n:=this.new,n[s]
}
else
{
if !dll
UnZipRawMemory(LockResource(LoadResource(0,ad:=FindResource(0,"F903E44B8A904483A1732BA84EA6191F",10))),SizeofResource(0,ad),dll)
f:=CriticalObject(),f[""]:=r:=MemoryLoadLibrary(&dll),f.fast:=func("ahkFast")
for i,n in {"fn":["ahkFunction","s==sssssssssss"],"fp":["ahkPostFunction","i==sssssssssss"],"new":["ahktextdll","ut==sss"]
,"add":["addScript","ut==si"],"exec":["ahkExec","ut==sui"],"get":["ahkgetvar","s==sui"],"set":["ahkassign","ui==ss"],"sub":["ahkLabel","ui==sui"]
,"pause":["ahkPause","i==s"],"end":["ahkTerminate","i==i"],"Ready":["ahkReady",""],"Reload":["ahkReload","i==i"]}
f[i]:=DynaCall(MemoryGetProcAddress(r,n.1),n.2)
if this!=""
ahkFast(f,this,code)
return f
}
}
Re: AHK_H: how to create an alias to a function from another thread?
Wow, that's some ugly soup of code.
I guess I'll just do this instead:
Much simpler.
I guess I'll just do this instead:
Code: Select all
global THREAD
func_name(params*){
return THREAD.ahkFunction('func_name',params*)
}
Re: AHK_H: how to create an alias to a function from another thread?
Would it be possible to use the pointer of a function as returned by ahkFindFunc to create an alias?
Example:
Example:
Code: Select all
myFunc := THREAD.ahkFindFunc('myFunc')
myFunc(params) ; <--- how to turn myFunc into a callable?
Re: AHK_H: how to create an alias to a function from another thread?
it would be nice if AHK_H had its own thread in Scripts & Functions (like it used to in the old forum), so that we could post questions directly there and HotKeyIt wouldn't miss them
Re: AHK_H: how to create an alias to a function from another thread?
Who decides if AHK_H gets it's own thread?
Can we create one?
Can we create one?
Re: AHK_H: how to create an alias to a function from another thread?
In the child thread, you would do something like this:
global SomeVar := ObjShare(Func("SomeFunc"))
The use something like this in the main thread to get the reference to the function:
this.MyThreadFunc := ObjShare(MyThread.ahkgetvar("SomeVar"))
This will give you a thread-safe way to call a function from a child thread
You can see an implementation of stuff like this in UCR.
Main thread: https://github.com/evilC/UCR/blob/maste ... le.ahk#L86
Child Thread: https://github.com/evilC/UCR/blob/maste ... ad.ahk#L36
global SomeVar := ObjShare(Func("SomeFunc"))
The use something like this in the main thread to get the reference to the function:
this.MyThreadFunc := ObjShare(MyThread.ahkgetvar("SomeVar"))
This will give you a thread-safe way to call a function from a child thread
You can see an implementation of stuff like this in UCR.
Main thread: https://github.com/evilC/UCR/blob/maste ... le.ahk#L86
Child Thread: https://github.com/evilC/UCR/blob/maste ... ad.ahk#L36
Last edited by evilC on 29 Nov 2016, 12:05, edited 2 times in total.
Re: AHK_H: how to create an alias to a function from another thread?
imo, HotKeyIt should decide, since its his project and he would be answering the questionsGetfree wrote:Who decides if AHK_H gets it's own thread?
Can we create one?
Re: AHK_H: how to create an alias to a function from another thread?
The alias can be also created using DynaCall:
______________________________________________________________________
I don't mind having separate thread for AHK_H.
Though I am not sure if I can decide, I think lexikos, tank and joedf need to agree.
Code: Select all
thread:=AhkThread("#Persistent`nfun(a*){`nMsgBox `% a.1 a.2 a.3`nreturn `"hello`"`n}")
fun:=DynaCall(MemoryGetProcAddress(thread[""],"ahkFunction"),["s==sssssssssss",2,3,4,5,6,7,8,9,10,11],"fun")
MsgBox % fun["Auto","Hot","Key"]
I don't mind having separate thread for AHK_H.
Though I am not sure if I can decide, I think lexikos, tank and joedf need to agree.
Re: AHK_H: how to create an alias to a function from another thread?
anyone can create a thread in Scripts & Functions forum for their own project. you had one in the old forumHotKeyIt wrote: I don't mind having separate thread for AHK_H.
Though I am not sure if I can decide, I think lexikos, tank and joedf need to agree.
Re: AHK_H: how to create an alias to a function from another thread?
Sorry, I mean forum section, not thread.
Thread will get quickly full and messy and people would still miss it and post else where.
Thread will get quickly full and messy and people would still miss it and post else where.
Re: AHK_H: how to create an alias to a function from another thread?
ah yes, an entire forum section for AHK_H might need approval. i think its overkill as well. i dont think AHK_H gets enough questions to really warrant its own forum section.HotKeyIt wrote:Sorry, I mean forum section, not thread.
even if AHK_H had its own section, people would still miss it and post else where. so the problem is likely the same. all posts could get merged into your Scripts & Functions thread. i think its better to have SOMETHING for now, where at least some people can go to for questions, and a place where you can easily find questionsHotKeyIt wrote:Thread will get quickly full and messy and people would still miss it and post else where.
Who is online
Users browsing this forum: No registered users and 32 guests