VBScipt:调用全局变量隐藏的内置函数

发布于 2024-08-08 20:33:37 字数 463 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静若繁花 2024-08-15 20:33:37

据我所知, 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.

小红帽 2024-08-15 20:33:37

我认为函数名称或变量不允许使用保留字。

邓肯森是对的。解决这个问题并重命名 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)

羁拥 2024-08-15 20:33:37

或者你可以使用CInt代替Int

response.write trim(cint(3.14)) + "<br>"

错误!!
查看NobodyMan 评论

Or you can use CInt instead on Int

response.write trim(cint(3.14)) + "<br>"

Wrong!!
See NobodyMan comments

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文