eval

How to cut off function from global scope

不打扰是莪最后的温柔 提交于 2019-12-11 17:14:57
问题 I have an idea for a game where people can type in some simple instructions for their character like player.goLeft() or player.attackInFront() and for that I have people type their code into a text box and then I parse it into eval(). This works well but it also allows people to change their own character object by typing things like player.health = Infinity; or something similar. I have a list of functions I want to allow people to use, but I am unsure how to restrict it to only use them. I

PHP eval() logical operator error

大憨熊 提交于 2019-12-11 16:58:34
问题 Why does if (isset($_SESSION['location']) AND !empty($_SESSION['location'])) work while if (isset($_SESSION['location']) && !empty($_SESSION['location'])) does not? I'm using eval() to process PHP in a wordpress page. It makes no sense to me why PHP chokes on && and not AND . The docs don't say anything specifically and no one else seems to have a clear answer. Thanks for your input. EDIT Not that it really matters, but I use eval() in a WP template: $sContent = get_the_content(); $sContent =

How to use .$$eval function

一世执手 提交于 2019-12-11 16:42:36
问题 I'm trying to run this code: var aaa = await page.$$eval(selector, list => (list, value) => { return resolve(list.find(element => element.textContent === value)); } ,value); But I received an error. Therefore, I tried to print the items in "list" (because I assumed that the problem is there), I tried this code: var aaa = await page.$$eval(selector, list => list); And I received that "aaa" is empty. Any idea what may be the problem? 回答1: You are attempting to return DOM elements from page.$

Memoize implementation using eval. Is this use of eval acceptable?

徘徊边缘 提交于 2019-12-11 12:56:33
问题 ...or are there better ways to implement a Memoization? Function.memoize = function(callableAsString) { var r = false, callable, code; try { callable = eval(callableAsString); if (typeof callable == "function" && typeof(Function.memoize.cache[callableAsString]) == "undefined") { code = callableAsString + " = function()" + "{" + "var cache = Function.memoize.cache['" + callableAsString + "'];" + "var k = Json.stringify([this].concat(arguments));" + "return cache.r[k] || (cache.r[k] = cache.c

How to EVAL a SELECT String and EXECUTE

China☆狼群 提交于 2019-12-11 11:57:33
问题 I wrote a function, StoogeFunk , that uses FOREACH against systables and syscolumns , to concatenate in a string the list of fields in a table (the name of which is passed as a function parameter). I surround with CAST/VARCHAR(30) the date fields, for reasons I dare not explain. So, I come to a point where I have in a string, SelectString , the equivalent of: SELECT Name, CAST(DOB AS VARCHAR(30)) AS DOB, ShoeSize FROM Stooges My function simply returns that LVARCHAR string (and it is a long

Creating an unevaluated function call with unevaluated arguments

血红的双手。 提交于 2019-12-11 11:40:48
问题 If we call a function directly in R, lazy evaluation takes place, so that the function arguments are not evaluated until they are encountered in the function body. An effect of this is that using match.call() at the beginning of a function, say a model fitter like lm , captures the call with unevaluated function arguments. Thus, the call to the function can be retrieved with promises instead of evaluated arguments by executing the model fitting function. The disadvantage of this is that the

How to evaluate an expression with variables in R?

血红的双手。 提交于 2019-12-11 10:59:06
问题 I expect this code to set plt equal to 10: > var = "plt" > eval(paste0(var, "<-", 10)) [1] "plt<-10" But instead, it returns a string. I tried eval(as.expression(paste0(var, "<-", 10))) and other options, but it still doesn't give the expected result. What's wrong with the code? 回答1: If I understand your comment correctly there is no reason to dive into the shark-infested waters of eval(parse()) . Try something like this instead: myfun <- function(x, fun) { if (is.character(fun)) fun <- match

JS求数组中最小值

99封情书 提交于 2019-12-11 10:27:52
var arr = [34, 12, 55, 27]; console.log( Math.min.apply(null, arr) ) // apply() console.log( Math.min(...arr) ) // 扩展运算符 console.log( eval("Math.min(" + arr.toString() + ")") ) //eval() console.log( arr.sort((a,b) =&gt; a - b)[0] ) // sort() var min = arr[0] arr.forEach(item => min > item ? item : null) console.log(min) //遍历 来源: 51CTO 作者: 喝醉的熊 链接: https://blog.51cto.com/13550695/2457577

Maintaining local variables between eval of code

筅森魡賤 提交于 2019-12-11 10:21:23
问题 Consider the following Ruby code: class Foo def bar; 42; end def run(code1,code2) binding.eval(code1,'c1') binding.eval(code2,'c2') end end Foo.new.run "x=bar ; p x", "p x" The intent is to dynamically evaluate some code—which creates local variables—and then run additional code that has access to those variables. The result is: c2:1:in `run': undefined local variable or method `x' for #<Foo:…> (NameError) Note that the above would only work if the eval mutated the binding, which it only does

.net 4 - run code from string - in C# / F# / IronRuby / IronPython

感情迁移 提交于 2019-12-11 10:18:19
问题 What ways do I have in .net to run code from string? Console.WriteLine(Compile("1 + 2 * 3")); // results is 7. What other options do we have? C# - Compile the code on runtime? IronRuby / IronPython? F#? 回答1: So, the dynamic languages like IronRuby and IronPython make it very easy to do what you want. Create a script engine and execute the string. Easy as that. C#, it is possible, using the Code DOM... but it it compiles the code every time into a DLL. This is a costly behavior and can cause