org.luaj.vm2.LuaThread Java Examples

The following examples show how to use org.luaj.vm2.LuaThread. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugLib.java    From luaj with MIT License 6 votes vote down vote up
public void onInstruction(int pc, Varargs v, int top) {
	LuaThread.State s = globals.running.state;
	if (s.inhook) return;
	callstack().onInstruction(pc, v, top);
	if (s.hookfunc == null) return;
	if (s.hookcount > 0)
		if (++s.bytecodes % s.hookcount == 0)
			callHook(s, COUNT, NIL);
	if (s.hookline) {
		int newline = callstack().currentline();
		if ( newline != s.lastline ) {
			s.lastline = newline;
			callHook(s, LINE, LuaValue.valueOf(newline));
		}
	}
}
 
Example #2
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread t = args.isthread(a) ? args.checkthread(a++) : globals.running;
    LuaValue func = args.optfunction(a++, null);
    String str = args.optjstring(a++, "");
    int count = args.optint(a++, 0);
    boolean call = false, line = false, rtrn = false;
    for (int i = 0; i < str.length(); i++)
        switch (str.charAt(i)) {
            case 'c':
                call = true;
                break;
            case 'l':
                line = true;
                break;
            case 'r':
                rtrn = true;
                break;
        }
    t.hookfunc = func;
    t.hookcall = call;
    t.hookline = line;
    t.hookcount = count;
    t.hookrtrn = rtrn;
    return NONE;
}
 
Example #3
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running; 
	LuaValue func    = args.optfunction(a++, null);
	String str       = args.optjstring(a++,"");
	int count        = args.optint(a++,0);
	boolean call=false,line=false,rtrn=false;
	for ( int i=0; i<str.length(); i++ )
		switch ( str.charAt(i) ) {
			case 'c': call=true; break;
			case 'l': line=true; break;
			case 'r': rtrn=true; break;
		}
	LuaThread.State s = t.state;
	s.hookfunc = func;
	s.hookcall = call;
	s.hookline = line;
	s.hookcount = count;
	s.hookrtrn = rtrn;
	return NONE;
}
 
Example #4
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
    LuaValue mt = table.opttable(null);
    switch (value.type()) {
        case TNIL:
            LuaNil.s_metatable = mt;
            break;
        case TNUMBER:
            LuaNumber.s_metatable = mt;
            break;
        case TBOOLEAN:
            LuaBoolean.s_metatable = mt;
            break;
        case TSTRING:
            LuaString.s_metatable = mt;
            break;
        case TFUNCTION:
            LuaFunction.s_metatable = mt;
            break;
        case TTHREAD:
            LuaThread.s_metatable = mt;
            break;
        default:
            value.setmetatable(mt);
    }
    return value;
}
 
Example #5
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running; 
	LuaValue func    = args.optfunction(a++, null);
	String str       = args.optjstring(a++,"");
	int count        = args.optint(a++,0);
	boolean call=false,line=false,rtrn=false;
	for ( int i=0; i<str.length(); i++ )
		switch ( str.charAt(i) ) {
			case 'c': call=true; break;
			case 'l': line=true; break;
			case 'r': rtrn=true; break;
		}
	LuaThread.State s = t.state;
	s.hookfunc = func;
	s.hookcall = call;
	s.hookline = line;
	s.hookcount = count;
	s.hookrtrn = rtrn;
	return NONE;
}
 
Example #6
Source File: CollectingOrphanedCoroutines.java    From luaj with MIT License 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
	// This timer controls how often each Java thread wakes up and checks if
	// it has been orhaned or not. A large number here will produce a long
	// delay between orphaning and colleciton, and a small number here will
	// consumer resources polling for orphaned status if there are many threads.
	LuaThread.thread_orphan_check_interval = 500;

	// Should work with standard or debug globals.
	Globals globals = JsePlatform.standardGlobals();
	// Globals globals = JsePlatform.debugGlobals();
	
	// Should work with plain compiler or lua-to-Java compiler.
	// org.luaj.vm2.luajc.LuaJC.install(globals);;

	// Load and run the script, which launches coroutines over and over forever.
	LuaValue chunk = globals.load(script, "main");
	chunk.call();
}
 
Example #7
Source File: DebugLib.java    From luaj with MIT License 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running;
	LuaValue func    = args.optfunction(a++, null);
	String str       = args.optjstring(a++,"");
	int count        = args.optint(a++,0);
	boolean call=false,line=false,rtrn=false;
	for ( int i=0; i<str.length(); i++ )
		switch ( str.charAt(i) ) {
			case 'c': call=true; break;
			case 'l': line=true; break;
			case 'r': rtrn=true; break;
		}
	LuaThread.State s = t.state;
	s.hookfunc = func;
	s.hookcall = call;
	s.hookline = line;
	s.hookcount = count;
	s.hookrtrn = rtrn;
	return NONE;
}
 
Example #8
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public void onInstruction(int pc, Varargs v, int top) {
    LuaThread t = globals.running;
    callstack().onInstruction(pc, v, top);

    if (t.inhook) return;
    if (t.hookfunc == null) return;
    if (t.hookcount > 0)
        if (++t.bytecodes % t.hookcount == 0)
            callHook(COUNT, NIL);
    if (t.hookline) {
        int newline = callstack().currentline();
        if (newline != t.lastline) {
            t.lastline = newline;
            callHook(LINE, LuaValue.valueOf(newline));
        }
    }
}
 
Example #9
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
public void onInstruction(int pc, Varargs v, int top) {
	LuaThread.State s = globals.running.state;
	if (s.inhook) return;
	callstack().onInstruction(pc, v, top);
	if (s.hookfunc == null) return;
	if (s.hookcount > 0)
		if (++s.bytecodes % s.hookcount == 0)
			callHook(s, COUNT, NIL);
	if (s.hookline) {
		int newline = callstack().currentline();
		if ( newline != s.lastline ) {
			s.lastline = newline;
			callHook(s, LINE, LuaValue.valueOf(newline));
		}
	}
}
 
Example #10
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public void onInstruction(int pc, Varargs v, int top) {
	LuaThread.State s = globals.running.state;
	if (s.inhook) return;
	callstack().onInstruction(pc, v, top);
	if (s.hookfunc == null) return;
	if (s.hookcount > 0)
		if (++s.bytecodes % s.hookcount == 0)
			callHook(s, COUNT, NIL);
	if (s.hookline) {
		int newline = callstack().currentline();
		if ( newline != s.lastline ) {
			s.lastline = newline;
			callHook(s, LINE, LuaValue.valueOf(newline));
		}
	}
}
 
Example #11
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void onCall(LuaClosure c, Varargs varargs, LuaValue[] stack) {
    LuaThread t = globals.running;
    callstack().onCall(c, varargs, stack);

    if (t.inhook) return;
    if (t.hookcall && t.hookfunc != null)
        callHook(CALL, NIL);
}
 
Example #12
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example #13
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    int level = args.checkint(a++);
    int local = args.checkint(a++);
    CallFrame f = callstack(thread).getCallFrame(level);
    return f != null ? f.getLocal(local) : NONE;
}
 
Example #14
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void onCall(LuaFunction f) {
    LuaThread t = globals.running;
    callstack().onCall(f);

    if (t.inhook) return;
    if (t.hookcall && t.hookfunc != null)
        callHook(CALL, NIL);
}
 
Example #15
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.getLocal(local): NONE;
}
 
Example #16
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void onReturn() {
    LuaThread t = globals.running;
    callstack().onReturn();

    if (t.inhook) return;
    if (t.hookcall && t.hookfunc != null)
        callHook(RETURN, NIL);
}
 
Example #17
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    String message = args.optjstring(a++, null);
    int level = args.optint(a++, 1);
    String tb = callstack(thread).traceback(level);
    return valueOf(message != null ? message + "\n" + tb : tb);
}
 
Example #18
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    int level = args.checkint(a++);
    int local = args.checkint(a++);
    LuaValue value = args.arg(a++);
    CallFrame f = callstack(thread).getCallFrame(level);
    return f != null ? f.setLocal(local, value) : NONE;
}
 
Example #19
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example #20
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaThread t = args.narg() > 0 ? args.checkthread(1): globals.running;
	LuaThread.State s = t.state;
	return varargsOf(
			s.hookfunc != null? s.hookfunc: NIL,
			valueOf((s.hookcall?"c":"")+(s.hookline?"l":"")+(s.hookrtrn?"r":"")),
			valueOf(s.hookcount));
}
 
Example #21
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	String message = args.optjstring(a++, null);
	int level = args.optint(a++,1);
	String tb = callstack(thread).traceback(level);
	return valueOf(message!=null? message+"\n"+tb: tb);
}
 
Example #22
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	LuaValue value = args.arg(a++);
	CallFrame f = callstack(thread).getCallFrame(level); 
	return f != null? f.setLocal(local, value): NONE;
}
 
Example #23
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	String message = args.optjstring(a++, null);
	int level = args.optint(a++,1);
	String tb = callstack(thread).traceback(level);
	return valueOf(message!=null? message+"\n"+tb: tb);
}
 
Example #24
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public LuaValue call(LuaValue value, LuaValue table) {
	LuaValue mt = table.opttable(null);
	switch ( value.type() ) {
		case TNIL:      LuaNil.s_metatable      = mt; break;
		case TNUMBER:   LuaNumber.s_metatable   = mt; break;
		case TBOOLEAN:  LuaBoolean.s_metatable  = mt; break;
		case TSTRING:   LuaString.s_metatable   = mt; break;
		case TFUNCTION: LuaFunction.s_metatable = mt; break;
		case TTHREAD:   LuaThread.s_metatable   = mt; break;
		default: value.setmetatable( mt );
	}
	return value;
}
 
Example #25
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	LuaValue value = args.arg(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.setLocal(local, value): NONE;
}
 
Example #26
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.getLocal(local): NONE;
}
 
Example #27
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.getLocal(local): NONE;
}
 
Example #28
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaThread t = args.narg() > 0 ? args.checkthread(1): globals.running;
	LuaThread.State s = t.state;
	return varargsOf(
			s.hookfunc != null? s.hookfunc: NIL,
			valueOf((s.hookcall?"c":"")+(s.hookline?"l":"")+(s.hookrtrn?"r":"")),
			valueOf(s.hookcount));
}
 
Example #29
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    LuaThread t = args.narg() > 0 ? args.checkthread(1) : globals.running;
    return varargsOf(
            t.hookfunc != null ? t.hookfunc : NIL,
            valueOf((t.hookcall ? "c" : "") + (t.hookline ? "l" : "") + (t.hookrtrn ? "r" : "")),
            valueOf(t.hookcount));
}
 
Example #30
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaThread t = args.narg() > 0 ? args.checkthread(1): globals.running;
	LuaThread.State s = t.state;
	return varargsOf(
			s.hookfunc != null? s.hookfunc: NIL,
			valueOf((s.hookcall?"c":"")+(s.hookline?"l":"")+(s.hookrtrn?"r":"")),
			valueOf(s.hookcount));
}