eval

Implementing JS Eval in C#

╄→尐↘猪︶ㄣ 提交于 2019-11-30 20:44:05
问题 Possible Duplicate: C# eval equivalent? Duplicate of How can I evaluate C# code dynamically? How can we Implement JS eval() in C# If possible provide an example.. thank you 回答1: You can actually use the JScript eval function from C#... Create a file JsMath.js, with the following JScript code : class JsMath { static function Eval(expression : String) : double { return eval(expression); }; } Compile it into a DLL : jsc /t:library JsMath.js Add a reference to JsMath.dll to your project. You can

R - Evaluate a nested function in an environment

懵懂的女人 提交于 2019-11-30 20:01:32
I am trying to run a chunk of R code in a sandbox-ed fashion, by loading all the necessary dependencies (functions and data) into a new environment and evaluating an expression within that environment. However, I'm running into trouble with functions calling other functions in the environment. Here's a simple example: jobenv <- new.env(parent=globalenv()) assign("f1", function(x) x*2, envir=jobenv) assign("f2", function(y) f1(y) + 1, envir=jobenv) expr <- quote(f2(3)) Using eval on expr fails since f2 can't find f1 > eval(expr, envir=jobenv) Error in f2(3) : could not find function "f1"

Initializing perl variables using eval

别等时光非礼了梦想. 提交于 2019-11-30 19:49:29
I'm guessing this should be something obvious to those knowing Perl, but I simply don't get it.. I also guess it has to do with problems described in Perl scoping « darkness - but I cannot apply any of that in my case. Anyways, here's the code: #!/usr/bin/env perl # call with: # ./test.pl use strict; my $tvars = "my \$varA = 1; my \$varB = 2; my \$varC = 3; "; my @lines = split /\n/, $tvars; foreach my $line (@lines) { print "$line\n"; eval $line; warn $@ if $@; } #~ print "$varA\n"; # Global symbol "$varA" requires explicit package name at ./test.pl line 18. #~ print "$varB\n"; # Global

How do I learn how to get quoting right in bash?

偶尔善良 提交于 2019-11-30 19:19:03
问题 I'm constantly confused by the rules for quoting and evaluating when I'm writing bash scripts. I know some of the basics, like the difference between '' and "" and ``, but I still seem to get it wrong far too often, and be reduced to experimenting with trying all sorts of different ways to say the same thing. Any individual problem I can usually work out by brute force, but I think my conceptual model of how it works must be hopelessly broken in some unknown way. I have no problem with lisp's

In PHP, is there a way to capture the output of a PHP file into a variable without using output buffering?

我们两清 提交于 2019-11-30 19:09:01
In PHP, I want to read a file into a variable and process the PHP in the file at the same time without using output buffering. Is this possible? Essentially I want to be able to accomplish this without using ob_start() : <?php ob_start(); include 'myfile.php'; $xhtml = ob_get_clean(); ?> Is this possible in PHP? Update: I want to do some more complex things within an output callback (where output buffering is not allowed). A little known feature of PHP is being able to treat an included/required file like a function call, with a return value. For example: // myinclude.php $value = 'foo';

Bash nested quotes and eval

淺唱寂寞╮ 提交于 2019-11-30 17:48:07
I'm having difficulty nested quotes within a bash script argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web" eval $argv The above got me eval: line 162: unexpected EOF while looking for matching `'' eval: line 163: syntax error: unexpected end of file argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web" That's because \' doesn't have any special meaning within a single-quoted string; it means simply "backslash, followed by end-of-string". One option is to use $'...' instead of '... '; that will let you use

PHP - templating with custom tags - is this a legit use of eval?

喜夏-厌秋 提交于 2019-11-30 17:11:52
问题 Overview Around the end of 2009, I wrote a simple templating system for PHP/HTML to be used in-house by our designers for brochure-ware type websites. The goal of the system is to allow templating in otherwise pure HTML via custom tags that are processed by PHP. For example, a templated page might look like this: <tt:Page template="templates/main.html"> <tt:Content name="leftColumn"> <p> blah blah </p> ... </tt:Content> <tt:Content name="rightColumn"> <p> blah blah </p> ... </tt:Content> </tt

Python - Zelle book uses eval(), is it wrong?

社会主义新天地 提交于 2019-11-30 16:57:34
问题 PLEASE NOTE: This is NOT about the use of eval(), it is about the potential quality (or lack thereof) of a book it is used and taught in. SO already has countless threads about eval() in Python. Risking to invite the wrath and downvotes of SO, I nonetheless decided to ask this question, just in case. Please bear with me. I've tried Google and SO itself for this specific question (as you will see) and got nothing. I might be blind, though. This question is about the use of the notorious eval()

PHP eval() code in between <?php ?> from database

笑着哭i 提交于 2019-11-30 16:30:54
问题 I want to be able to put PHP into the database and run it. I have to do this because I store page layouts in the database and each our different for each other, however in some cases I want to use dynamic content for some of the pages. Assume $query_from_db is the string returned from the database. PHP should only eval() the code in between <?php and ?> $query_from_db = '<div> <?php //php to run function dosomething() { //bleh } ?> </div> '; php echo eval($query_from_db); How can I do this? I

Convert string to executable code at run time in c#?

微笑、不失礼 提交于 2019-11-30 16:21:06
Is there any way I can convert a string of code into executable code at runtime in c#? So if I have a file of predicates This is normal text in a txt file u => u.Contains("android") && u.Contains("webkit") u => u.Contains("iphone") && u.Contains("webkit") I would want to read it in via my program and then capture each predicate as a string and then convert it to code on the fly. Something like: string[] predicates = ///get file contentsa foreach(var predicate in predicates) { if(userAgent.ConformsTo(eval(predicate))) return true; } You can use CSharpCodeProvider class, but you'll need to build