lua - Lua:调用函数时获取传递的参数
问题描述
我想获取传递给特定函数的参数。
例如:
load("return 2+1")()
想要的输出:
return 2+1
阅读调试库后我不知道:(
解决方案
如果我正确理解您想要什么,请在调用之前覆盖加载函数:
local global_load = load
local function load (...)
print (...) -- or use whatever debug tool to see the arguments.
return global_load (...)
end
您可以通过这种方式重新定义任何函数:
local function verbose (func)
return function (...)
print (...) -- or use whatever debug tool to see the arguments.
return func (...)
end
end
local load = verbose (load)
print (load 'return 2 + 1' ())
推荐阅读
- postgresql - RDS Postgres DB IAM generate_db_auth_token 不工作
- javascript - 如何通过输入值检查数组值?
- python-3.x - ModuleNotFoundError 使用 items.py
- java - 如何将列表转换为地图
>> 使用 java lambda? - php - 从表单字段解析 Laravel 变量
- oauth - AWS Cognito 和 Grafana 'login.OAuthLogin(missing saved state)' 并且无法像其他任何人一样登录
- html - css中的.class不能正常工作如何解决?
- flutter - 如何在颤动中通过页面转换转到第二页?
- smarty - 在 Smarty 2 模板中的变量内使用变量
- java - Java 和 Hadoop 显然没有正确安装