可用于RMMV的JavaScript的Native函数
这些函数没有被列在F1文档中(或者我没找到),在JS教程中通常会存在。不过我所找到的是直接使用F8调试查询到的可确保用于RMMV的函数。
因此提供这些方便的函数,也许你会需要。
暂时没有翻译,因为我暂时还没用到这些功能。
JAVASCRIPT 代码
function StringConstructor(a){
if( % _ArgumentsLength() == 0) a = '';
if( % _IsConstructCall()){ % _SetValueOf(this, ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)));
}else{
return(typeof(a) === 'symbol') ?
% _CallFunction(a, SymbolToString) : ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
}
}
function StringToString(){
if(!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')){
thrownew $TypeError('String.prototype.toString is not generic');
}
return %_ValueOf(this);
}
function StringValueOf(){
if(!(typeof(this) === 'string') && !( % _ClassOf(this) === 'String')){
thrownew $TypeError('String.prototype.valueOf is not generic');
}
return %_ValueOf(this);
}
function StringCharAt(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charAt"]);
var b = % _StringCharAt(this, a);
if( % _IsSmi(b)){
b = % _StringCharAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
}
return b;
}
function StringCharCodeAt(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.charCodeAt"]);
var b = % _StringCharCodeAt(this, a);
if(! % _IsSmi(b)){
b = % _StringCharCodeAt(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a))));
}
return b;
}
function StringConcat(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.concat"]);
var b = % _ArgumentsLength();
var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
if(b === 1){
return c + a;
}
var d = new InternalArray(b + 1);
d = c;
for(var g = 0; g < b; g++){
var h = % _Arguments(g);
d = ((typeof( % IS_VAR(h)) === 'string') ? h : NonStringToString(h));
}
return %StringBuilderConcat(d, b + 1, "");
}
function StringIndexOfJS(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.indexOf"]);
var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
var c = 0;
if( % _ArgumentsLength() > 1){
c = % _Arguments(1);
c = ( % _IsSmi( % IS_VAR(c)) ? c : % NumberToInteger(ToNumber(c)));
if(c < 0) c = 0;
if(c > b.length) c = b.length;
}
return %StringIndexOf(b, a, c);
}
function StringLastIndexOfJS(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.lastIndexOf"]);
var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
var c = b.length;
var a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
var d = a.length;
var g = c - d;
if( % _ArgumentsLength() > 1){
var h = ToNumber( % _Arguments(1));
if(!(! % _IsSmi( % IS_VAR(h)) && !(h == h))){
h = ( % _IsSmi( % IS_VAR(h)) ? h : % NumberToInteger(ToNumber(h)));
if(h < 0){
h = 0;
}
if(h + d < c){
g = h;
}
}
}
if(g < 0){
return-1;
}
return %StringLastIndexOf(b, a, g);
}
function StringLocaleCompareJS(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.localeCompare"]);
return %StringLocaleCompare(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)));
}
function StringMatchJS(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.match"]);
var b = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
if(( % _IsRegExp(a))){
var c = a.lastIndex;
( % _IsSmi( % IS_VAR(c)) ? c : ToNumber(c));
if(!a.global)return RegExpExecNoTests(a, b, 0);
var d = % StringMatch(b, a, lastMatchInfo);
if(d !== null) lastMatchInfoOverride = null;
a.lastIndex = 0;
return d;
}
a = new $RegExp(a);
return RegExpExecNoTests(a, b, 0);
}
var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
function StringNormalizeJS(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.normalize"]);
var a = a ? ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)) : 'NFC';
var b = NORMALIZATION_FORMS.indexOf(a);
if(b === -1){
thrownew $RangeError('The normalization form should be one of ' + NORMALIZATION_FORMS.join(', ') + '.');
}
return %_ValueOf(this);
}
var reusableMatchInfo = ;
function StringReplace(a, b){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.replace"]);
var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
if(( % _IsRegExp(a))){
var d = a.lastIndex;
( % _IsSmi( % IS_VAR(d)) ? d : ToNumber(d));
if(!( % _ClassOf(b) === 'Function')){
b = ((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b));
if(!a.global){
var g = DoRegExpExec(a, c, 0);
if(g == null){
a.lastIndex = 0
return c;
}
if(b.length == 0){
return %_SubString(c, 0, g) +
% _SubString(c, g, c.length)
}
return ExpandReplacement(b, c, lastMatchInfo, % _SubString(c, 0, g)) +
% _SubString(c, g, c.length);
}
a.lastIndex = 0;
if(lastMatchInfoOverride == null){
return %StringReplaceGlobalRegExpWithString(
c, a, b, lastMatchInfo);
}else{
var h = lastMatchInfo;
lastMatchInfo = 0;
var i = % StringReplaceGlobalRegExpWithString(
c, a, b, lastMatchInfo);
if( % _IsSmi(lastMatchInfo)){
lastMatchInfo = h;
}else{
lastMatchInfoOverride = null;
}
return i;
}
}
if(a.global){
return StringReplaceGlobalRegExpWithFunction(c, a, b);
}
return StringReplaceNonGlobalRegExpWithFunction(c, a, b);
}
a = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
if(a.length == 1 &&
c.length > 0xFF &&
(typeof(b) === 'string') &&
% StringIndexOf(b, '$', 0) < 0){
return %StringReplaceOneCharWithString(c, a, b);
}
var j = % StringIndexOf(c, a, 0);
if(j < 0)return c;
var k = j + a.length;
var l = % _SubString(c, 0, j);
if(( % _ClassOf(b) === 'Function')){
var m = % GetDefaultReceiver(b);
l += % _CallFunction(m, a, j, c, b);
}else{
reusableMatchInfo = j;
reusableMatchInfo = k;
l = ExpandReplacement(((typeof( % IS_VAR(b)) === 'string') ? b : NonStringToString(b)),
c,
reusableMatchInfo,
l);
}
return l + % _SubString(c, k, c.length);
}
function ExpandReplacement(a, b, c, d){
var g = a.length;
var h = % StringIndexOf(a, '$', 0);
if(h < 0){
if(g > 0) d += a;
return d;
}
if(h > 0) d += % _SubString(a, 0, h);
while(true){
var i = '$';
var j = h + 1;
if(j < g){
var k = % _StringCharCodeAt(a, j);
if(k == 36){
++j;
d += '$';
}elseif(k == 38){
++j;
d +=
% _SubString(b, c, c);
}elseif(k == 96){
++j;
d += % _SubString(b, 0, c);
}elseif(k == 39){
++j;
d += % _SubString(b, c, b.length);
}elseif(k >= 48 && k > 11) + (m & 0x7ff);
}else{
i = g[++l] - m;
}
}else{
j = m;
j = i;
lastMatchInfoOverride = j;
var o = % _CallFunction(k, m, i, a, c);
g = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
i += m.length;
}
}
}else{
var k = % GetDefaultReceiver(c);
for(var l = 0; l < h; l++){
var m = g;
if(! % _IsSmi(m)){
lastMatchInfoOverride = m;
var o = % Apply(c, k, m, 0, m.length);
g = ((typeof( % IS_VAR(o)) === 'string') ? o : NonStringToString(o));
}
}
}
var q = % StringBuilderConcat(g, g.length, a);
d.length = 0;
reusableReplaceArray = d;
return q;
}
function StringReplaceNonGlobalRegExpWithFunction(a, b, c){
var d = DoRegExpExec(b, a, 0);
if((d === null)){
b.lastIndex = 0;
return a;
}
var g = d;
var h = % _SubString(a, 0, g);
var i = d;
var j = ((d)) >> 1;
var k;
var l = % GetDefaultReceiver(c);
if(j == 1){
var m = % _SubString(a, g, i);
k = % _CallFunction(l, m, g, a, c);
}else{
var o = new InternalArray(j + 2);
for(var q = 0; q < j; q++){
o = CaptureString(a, d, q);
}
o = g;
o = a;
k = % Apply(c, l, o, 0, q + 2);
}
h += k;
return h + % _SubString(a, i, a.length);
}
function StringSearch(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.search"]);
var b;
if((typeof(a) === 'string')){
b = % _GetFromCache(0, a);
}elseif(( % _IsRegExp(a))){
b = a;
}else{
b = new $RegExp(a);
}
var c = DoRegExpExec(b, ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), 0);
if(c){
return c;
}
return-1;
}
function StringSlice(a, b){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.slice"]);
var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
var d = c.length;
var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
var h = d;
if(!(b === (void0))){
h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
}
if(g < 0){
g += d;
if(g < 0){
g = 0;
}
}else{
if(g > d){
return'';
}
}
if(h < 0){
h += d;
if(h < 0){
return'';
}
}else{
if(h > d){
h = d;
}
}
if(h >> 0);
var d = c.length;
if(!( % _IsRegExp(a))){
var g = ((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a));
if(b === 0)return[];
if((a === (void0)))return;
var h = g.length;
if(h === 0)return %StringToArray(c, b);
var i = % StringSplit(c, g, b);
return i;
}
if(b === 0)return[];
return StringSplitOnRegExp(c, a, b, d);
}
function StringSplitOnRegExp(a, b, c, d){
if(d === 0){
if(DoRegExpExec(b, a, 0, 0) != null){
return[];
}
return;
}
var g = 0;
var h = 0;
var i = 0;
var j = new InternalArray();
outer_loop:
while(true){
if(h === d){
j = % _SubString(a, g, d);
break;
}
var k = DoRegExpExec(b, a, h);
if(k == null || d === (i = k)){
j = % _SubString(a, g, d);
break;
}
var l = k;
if(h === l && l === g){
h++;
continue;
}
j = % _SubString(a, g, i);
if(j.length === c)break;
var m = ((k)) + 3;
for(var o = 3 + 2; o < m;){
var q = k;
var r = k;
if(r != -1){
j = % _SubString(a, q, r);
}else{
j = (void0);
}
if(j.length === c)break outer_loop;
}
h = g = l;
}
var t = []; % MoveArrayContents(j, t);
return t;
}
function StringSubstring(a, b){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.subString"]);
var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
var d = c.length;
var g = ( % _IsSmi( % IS_VAR(a)) ? a : % NumberToInteger(ToNumber(a)));
if(g < 0){
g = 0;
}elseif(g > d){
g = d;
}
var h = d;
if(!(b === (void0))){
h = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
if(h > d){
h = d;
}else{
if(h < 0) h = 0;
if(g > h){
var i = h;
h = g;
g = i;
}
}
}
return %_SubString(c, g, h);
}
function StringSubstr(a, b){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.substr"]);
var c = ((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this));
var d;
if((b === (void0))){
d = c.length;
}else{
d = ( % _IsSmi( % IS_VAR(b)) ? b : % NumberToInteger(ToNumber(b)));
if(d = c.length)return'';
if(a < 0){
a += c.length;
if(a < 0) a = 0;
}
}
var g = a + d;
if(g > c.length) g = c.length;
return %_SubString(c, a, g);
}
function StringToLowerCaseJS(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLowerCase"]);
return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
}
function StringToLocaleLowerCase(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleLowerCase"]);
return %StringToLowerCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
}
function StringToUpperCaseJS(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toUpperCase"]);
return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
}
function StringToLocaleUpperCase(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.toLocaleUpperCase"]);
return %StringToUpperCase(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)));
}
function StringTrimJS(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trim"]);
return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, true);
}
function StringTrimLeft(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimLeft"]);
return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), true, false);
}
function StringTrimRight(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.trimRight"]);
return %StringTrim(((typeof( % IS_VAR(this)) === 'string') ? this : NonStringToString(this)), false, true);
}
function StringFromCharCode(a){
var b = % _ArgumentsLength();
if(b == 1){
if(! % _IsSmi(a)) a = ToNumber(a);
return %_StringCharFromCode(a & 0xffff);
}
var c = % NewString(b, true);
var d;
for(d = 0; d < b; d++){
var a = % _Arguments(d);
if(! % _IsSmi(a)) a = ToNumber(a) & 0xffff;
if(a < 0) a = a & 0xffff;
if(a > 0xff)break; % _OneByteSeqStringSetChar(d, a, c);
}
if(d == b)return c;
c = % TruncateString(c, d);
var g = % NewString(b - d, false);
for(var h = 0; d < b; d++, h++){
var a = % _Arguments(d);
if(! % _IsSmi(a)) a = ToNumber(a) & 0xffff; % _TwoByteSeqStringSetChar(h, a, g);
}
return c + g;
}
function HtmlEscape(a){
return((typeof( % IS_VAR(a)) === 'string') ? a : NonStringToString(a)).replace(/"/g, """);
}
function StringAnchor(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.anchor"]);
return"" + this + "";
}
function StringBig(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.big"]);
return"" + this + "";
}
function StringBlink(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.blink"]);
return"" + this + "";
}
function StringBold(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.bold"]);
return"" + this + "";
}
function StringFixed(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fixed"]);
return"" + this + "";
}
function StringFontcolor(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontcolor"]);
return"" + this + "";
}
function StringFontsize(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.fontsize"]);
return"" + this + "";
}
function StringItalics(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.italics"]);
return"" + this + "";
}
function StringLink(a){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.link"]);
return"" + this + "";
}
function StringSmall(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.small"]);
return"" + this + "";
}
function StringStrike(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.strike"]);
return"" + this + "";
}
function StringSub(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sub"]);
return"" + this + "";
}
function StringSup(){
if((this == null) && !( % _IsUndetectableObject(this)))throw MakeTypeError('called_on_null_or_undefined', ["String.prototype.sup"]);
return"" + this + "";
}
function SetUpString(){ % CheckIsBootstrapping(); % SetCode($String, StringConstructor); % FunctionSetPrototype($String, new $String()); % AddNamedProperty($String.prototype, "constructor", $String, 2);
InstallFunctions($String, 2, $Array(
"fromCharCode", StringFromCharCode
));
InstallFunctions($String.prototype, 2, $Array(
"valueOf", StringValueOf,
"toString", StringToString,
"charAt", StringCharAt,
"charCodeAt", StringCharCodeAt,
"concat", StringConcat,
"indexOf", StringIndexOfJS,
"lastIndexOf", StringLastIndexOfJS,
"localeCompare", StringLocaleCompareJS,
"match", StringMatchJS,
"normalize", StringNormalizeJS,
"replace", StringReplace,
"search", StringSearch,
"slice", StringSlice,
"split", StringSplitJS,
"substring", StringSubstring,
"substr", StringSubstr,
"toLowerCase", StringToLowerCaseJS,
"toLocaleLowerCase", StringToLocaleLowerCase,
"toUpperCase", StringToUpperCaseJS,
"toLocaleUpperCase", StringToLocaleUpperCase,
"trim", StringTrimJS,
"trimLeft", StringTrimLeft,
"trimRight", StringTrimRight,
"link", StringLink,
"anchor", StringAnchor,
"fontcolor", StringFontcolor,
"fontsize", StringFontsize,
"big", StringBig,
"blink", StringBlink,
"bold", StringBold,
"fixed", StringFixed,
"italics", StringItalics,
"small", StringSmall,
"strike", StringStrike,
"sub", StringSub,
"sup", StringSup
));
}
SetUpString();
本帖来自P1论坛作者MonsterJohnCN,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=384597若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]