Improve get name for func.

This commit is contained in:
Enyby
2019-10-20 06:45:53 +03:00
parent 169202362e
commit 5fe0a3950d
2 changed files with 19 additions and 16 deletions

View File

@@ -22,14 +22,14 @@
package org.luaj.vm2; package org.luaj.vm2;
/** /**
* Base class for functions implemented in Java. * Base class for functions implemented in Java.
* <p> * <p>
* Direct subclass include {@link org.luaj.vm2.lib.LibFunction} * Direct subclass include {@link org.luaj.vm2.lib.LibFunction}
* which is the base class for * which is the base class for
* all built-in library functions coded in Java, * all built-in library functions coded in Java,
* and {@link LuaClosure}, which represents a lua closure * and {@link LuaClosure}, which represents a lua closure
* whose bytecode is interpreted when the function is invoked. * whose bytecode is interpreted when the function is invoked.
* @see LuaValue * @see LuaValue
* @see LuaClosure * @see LuaClosure
* @see org.luaj.vm2.lib.LibFunction * @see org.luaj.vm2.lib.LibFunction
@@ -57,11 +57,11 @@ public class LuaFunction extends LuaValue {
} }
public LuaFunction optfunction(LuaFunction defval) { public LuaFunction optfunction(LuaFunction defval) {
return this; return this;
} }
public LuaValue getmetatable() { public LuaValue getmetatable() {
return s_metatable; return s_metatable;
} }
public String tojstring() { public String tojstring() {
@@ -72,12 +72,15 @@ public class LuaFunction extends LuaValue {
return valueOf(tojstring()); return valueOf(tojstring());
} }
/** Return the last part of the class name, to be used as a function name in tojstring and elsewhere. /** Return the last part of the class name, to be used as a function name in tojstring and elsewhere.
* @return String naming the last part of the class name after the last dot (.) or dollar sign ($). * @return String naming the last part of the class name after the last dot (.) or dollar sign ($).
* If the first character is '_', it is skipped.
*/ */
public String classnamestub() { public String classnamestub() {
String s = getClass().getName(); String s = getClass().getName();
return s.substring(Math.max(s.lastIndexOf('.'),s.lastIndexOf('$'))+1); int offset = Math.max(s.lastIndexOf('.'), s.lastIndexOf('$')) + 1;
if (s.charAt(offset) == '_') offset++;
return s.substring(offset);
} }
/** Return a human-readable name for this function. Returns the last part of the class name by default. /** Return a human-readable name for this function. Returns the last part of the class name by default.

View File

@@ -83,8 +83,8 @@ public class StringLib extends TwoArgFunction {
*/ */
public LuaValue call(LuaValue modname, LuaValue env) { public LuaValue call(LuaValue modname, LuaValue env) {
LuaTable string = new LuaTable(); LuaTable string = new LuaTable();
string.set("byte", new byte_()); string.set("byte", new _byte());
string.set("char", new char_()); string.set("char", new _char());
string.set("dump", new dump()); string.set("dump", new dump());
string.set("find", new find()); string.set("find", new find());
string.set("format", new format()); string.set("format", new format());
@@ -117,7 +117,7 @@ public class StringLib extends TwoArgFunction {
* *
* @param args the calling args * @param args the calling args
*/ */
static final class byte_ extends VarArgFunction { static final class _byte extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
LuaString s = args.checkstring(1); LuaString s = args.checkstring(1);
int l = s.m_length; int l = s.m_length;
@@ -148,7 +148,7 @@ public class StringLib extends TwoArgFunction {
* *
* @param args the calling VM * @param args the calling VM
*/ */
static final class char_ extends VarArgFunction { static final class _char extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
int n = args.narg(); int n = args.narg();
byte[] bytes = new byte[n]; byte[] bytes = new byte[n];