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 Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #2
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #3
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #4
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #5
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #6
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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 #7
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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 #8
Source Project: luaj   Author: luaj   File: CollectingOrphanedCoroutines.java    License: 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 #9
Source Project: luaj   Author: luaj   File: DebugLib.java    License: 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 #10
Source Project: luaj   Author: luaj   File: DebugLib.java    License: 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 #11
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #12
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #13
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #14
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #15
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #16
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #17
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: DebugLib.java    License: 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 #18
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #19
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #20
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #21
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #22
Source Project: XPrivacyLua   Author: M66B   File: DebugLib.java    License: 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 #23
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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));
}
 
Example #24
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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 #25
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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 #26
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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 #27
Source Project: HtmlNative   Author: hsllany   File: DebugLib.java    License: 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; 
	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 #28
Source Project: luaj   Author: luaj   File: DebugLib.java    License: 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 Project: luaj   Author: luaj   File: DebugLib.java    License: 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 #30
Source Project: luaj   Author: luaj   File: DebugLib.java    License: 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;
}