简体   繁体   中英

Is there a way to make a custom loadstring() function in lua?

Here is an example

local CustomLoad = function(l) loadstring(l) end

CustomLoad("print('hi')")

Please let me know, beacuse I got into this like a week ago, and I've been trying to make it, yet I coudln't. Can some of you tell me if it's even possible?

If you aren't trying to run "print('hi')" in that example, then I do believe you're missing a return statement.

local CustomLoad = function(l) return loadstring(l) end

But if you are, then:

local CustomLoad = function(l) return loadstring(l) end
CustomLoad("print('hi')")()

or

local CustomLoad = function(l) local f = loadstring(l); f() end
CustomLoad("print('hi')")

Because loadstring creates a function, which, when run, executes the code in the string. Hope that helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM