How can I call a pact module on chain using passed in module+defun name - pact-lang

I have a contract that is able to call another module on chain from within itself, and it is working as follows:
(defun call-other(nft-id)
(mod-2.defun-name ...params)
I am trying to do it dynamically by passing module name of "mod-2" to the defun, and hopefully using a symbol to call mod-2 dynamically but it cant resolve mod.
Ideal:
(defun call-other(nft-id:string mod:string)
('mod.defun-name ...params )
Any ideas would be greatly appreciated

You can pass modules as params and call them as follows :
(From Babena marm implementations; awesome job folks and thanks!)
calling from defun
passing through env-data

Related

Is there a way to get all tf.variables used in a function?

Given a function, is there a way to extract the tensorflow variables that are used in it? (The framework must somehow do this when a function is passed to an optimizer)
I cannot understand what you say exactly.
But If you are talking about getting value from tensor, there are some ways to do that.
tensor.data() and tensor.dataSync()
Reference:
https://js.tensorflow.org/api/0.11.2/#tf.Tensor.data

How to insert print for each function of C language for debugging?

I am studying and debugging one software. There are thousands of functions in this software. I plan to add printf() at the entry and exit point of each function. It will take a lot of time.
Is there one tool/script to do this?
I may use '__cyg_profile_func_enter'. But it can only get address. But I have to run another script to get function name. I also hope to get value of input parameters of this function too.
You should give a try to AOP : Aspect Oriented Programming. Personnaly I've only tried with Java and Spring AOP but there's an API for C too : AspectC (https://sites.google.com/a/gapp.msrg.utoronto.ca/aspectc/home). From what I've seen, it's not the only one.
From what I've red about this library, you can add an pointcut before compiling with AspectC :
// before means it's a before function aspect
// call means it's processed when a function is called
// args(...) means it applies to any function with any arguments
// this->funcName is the name of the function handled by AspectC
before(): call(args(...)) {
printf("Entering %s\n", this->funcName);
}
(not tried by myself but extracted from the reference page https://sites.google.com/a/gapp.msrg.utoronto.ca/aspectc/tutorial)
This is only a basic overview of what can be done and you still have to deal with the compilation (documented in the page linked before) but it looks like it could possibly help you. Give a try with a simple POC maybe.

Wrapping Ruby With An Anonymous Module

There are several Ruby C API functions for running some Ruby code. Most just run the code in an isolated binding like require does. But some of them first wrap the code in an anonymous module before running it. For example, rb_load takes an argument for whether you want this wrapping, rb_eval_string_wrap is just rb_eval_string_protect but with wrapping.
In C, the wrapping looks like this:
/* load in anonymous module as toplevel */
th->top_self = rb_obj_clone(rb_vm_top_self());
th->top_wrapper = rb_module_new();
rb_extend_object(th->top_self, th->top_wrapper);
What is the point of doing this? I've tested these functions alongside their unwrapped equivalents and the result is always the same. Is there some use-case I'm not seeing?
I should've done some more testing. It looks like this is a bug.
The point of wrapping code in an anonymous module is to not pollute the toplevel namespace with constants/methods defined in the code. rb_load does this wrapping properly, rb_eval_string_wrap does not.

How can I get the methods defined in a module?

I'm trying to consume an F# assembly from Fsi, but can't seem to find a way to get a list of methods defined in a module so I can call them.
Here's a sample file I'm trying to do this with. In following the "exposing methods that are cross language friendly", I've added a namespace to the top of the file and added a module to contain the let bound methods that were there previously. I'd like to avoid moving everything into static classes if possible.
Can I use reflection, or write the module in another way that helps me find the available methods and proper casing of the methods?
If I correctly understood the problem, I would proceed as follows:
1) Get the desired assembly. For example, the assembly that is currently being executed can be obtained by
System.Reflection.Assembly.GetExecutingAssembly
2) Then I would take all the types defined in the obtained assembly by calling GetTypes. If you want to filter out modules you could write something like.
let modules = Array.filter (fun x -> FSharpType.IsModule x) (assembly.GetTypes())
The documentation for the FSharpType class can be found here. It is included in the Microsoft.FSharp.Reflection namespace.
3) After, you can obtain the methods in a module by calling GetMethods method on a single module. For example, to print them all, you could write something like:
let methods = [| for t in modules do for m in t.GetMethods() -> m |]
for m in methods do
printfn "%A" m
methods is an array containing MethodInfo elements. GetMethods takes an optional parameter of type BindingFlags that can filter out some methods. Take a look at the documentation.
You can also invoke actions by calling the Invoke method on a MethodInfo object.
Hope this was useful.

Ruby C Extension using Singleton

I only wanted to allow one instance of my C extension class to be made, so I wanted to include the singleton module.
void Init_mousetest() {
VALUE mouseclass = rb_define_class("MyMouse",rb_cObject);
rb_require("singleton");
VALUE singletonmodule = rb_const_get(rb_cObject,rb_intern("Singleton"));
rb_include_module(mouseclass,singletonmodule);
rb_funcall(singletonmodule,rb_intern("included"),1,mouseclass);
### ^ Why do I need this line here?
rb_define_method(mouseclass,"run",method_run,0);
rb_define_method(mouseclass,"spawn",method_spawn,0);
rb_define_method(mouseclass,"stop",method_stop,0);
}
As I understand it, what that line does is the same as Singleton.included(MyMouse), but if I try to invoke that, I get
irb(main):006:0> Singleton.included(MyMouse)
NoMethodError: private method `included' called for Singleton:Module
from (irb):6
from C:/Ruby19/bin/irb:12:in `<main>'
Why does rb_include_module behave differently than I would expect it to? Also any tangential discussions/explanations or related articles are appreciated. Ruby beginner here.
Also it seems like I could have just kept my extension as simple as possible and just hack some kind of interface later on to ensure I only allow one instance. Or just put my mouse related methods into a module... Any of that make sense?
according to http://www.groupsrv.com/computers/about105620.html the rb_include_module() is actually just Module#append_features.
Apparently Module#include calls Module#append_features and Module#included. So in our C code we must also call included. Since clearly something important happens there.

Resources