VBScipt:调用全局变量隐藏的内置函数
ASP Classic 上的 VBScript 包含一个“int”函数。 (它将数字向 -∞ 舍入。)假设某个过于“聪明”的编码器创建了一个名为“int”的全局变量。有什么办法可以得到原来的功能吗?我已经对范围界定和狡猾的高管尝试了各种解决方法,但没有成功。我怀疑这是不可能的,但我希望有人比我更了解它。
编辑:感谢您的回复。既然你们都问了,全局变量,称为“Int”(不幸的是,vbscript 不区分大小写),是一个类似于 Java 的 Integer 类的工厂。默认属性本质上是一个单参数构造函数;即“Int(42)”产生一个新的 IntClass 对象,其中包含 42。IntClass 的默认属性又简单地返回原始数字。
创建者试图解决缺乏适当的命名空间和静态方法的问题,并且该解决方案实际上非常无缝。传入一个 IntClass ,其中需要 int ,它将自动触发默认属性。我正在尝试修补最后剩下的接缝:调用“int”的外部代码将无法正确舍入(因为构造函数使用 CLng)。
VBScript on ASP Classic contains an "int" function. (It rounds numbers towards -∞.) Suppose that some excessively "clever" coder has created a global variable named "int". Is there any way to get at the original function? I've tried all manner of workarounds with scoping and dodgy execs, but no dice. I suspect that it is impossible, but I'm hoping that someone will know more about it than I do.
EDIT: Thanks for the responses. Since y'all asked, the global variable, called "Int" (though unfortunately, vbscript is not case-sensitive), is a factory for a class similar to Java's Integer. The default property is essentially a one-arg constructor; i.e. "Int(42)" yields a new IntClass object holding 42. The default property of IntClass in turn simply returns the raw number.
The creator was trying to work around the lack of proper namespaces and static methods, and the solution's actually pretty seamless. Pass in an IntClass where an int is expected and it will automatically trigger the default property. I'm trying to patch the last remaining seam: that external code calling "int" will not round properly (because the constructor uses CLng).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知, getref 仅适用于自定义函数,不适用于内置函数。我建议重命名自定义“int”函数并更新对此自定义函数的所有引用。您可以使用 Visual Studio (express) 的搜索功能或您喜欢的任何其他工具来执行此操作。不应该做太多工作。
Not that I know of, getref only works on custom functions not on build-ins. I would suggest renaming the custom'int' function and update all references to this custom ones. You can use the search function visual studio (express) or any other tool of your liking for this. Shouldn't be to much work.
我认为函数名称或变量不允许使用保留字。
邓肯森是对的。解决这个问题并重命名 int。很可能还有比这更糟糕的事情发生。
(为什么有人会创建一个名为 int 的全局变量......这需要一些思考)
I didn't think reserved words would be allowed for function names or variables.
Duncanson's right. Do the pain and rename int. Chances are there are worse things going on than just this.
(why would someone make a global variable named int... that's going to take some thinking)
或者你可以使用CInt
代替Int
错误!!
查看NobodyMan 评论
Or you can useCInt
instead onInt
Wrong!!
See NobodyMan comments