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

@@ -74,10 +74,13 @@ public class LuaFunction extends LuaValue {
/** 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 ($).
* If the first character is '_', it is skipped.
*/
public String classnamestub() {
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.

View File

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