anonl / nvlist
Showing 13 of 32 files from the diff.

@@ -188,7 +188,7 @@
Loading
188 188
189 189
    @Override
190 190
    public void loadScript(IScriptThread thread, FilePath filename) throws ScriptException {
191 -
        LuaScriptThread luaThread = (LuaScriptThread)thread;
191 +
        ILuaScriptThread luaThread = (ILuaScriptThread)thread;
192 192
193 193
        Varargs loadResult = ScriptLoader.loadFile(filename.toString());
194 194
        if (!loadResult.arg1().isclosure()) {

@@ -13,8 +13,8 @@
Loading
13 13
import nl.weeaboo.vn.core.IContextListener;
14 14
import nl.weeaboo.vn.core.ISkipState;
15 15
import nl.weeaboo.vn.impl.scene.Screen;
16 +
import nl.weeaboo.vn.impl.script.lua.ILuaScriptThread;
16 17
import nl.weeaboo.vn.impl.script.lua.LuaScriptContext;
17 -
import nl.weeaboo.vn.impl.script.lua.LuaScriptThread;
18 18
import nl.weeaboo.vn.impl.signal.SignalUtil;
19 19
import nl.weeaboo.vn.input.IInput;
20 20
import nl.weeaboo.vn.render.IDrawBuffer;
@@ -113,7 +113,7 @@
Loading
113 113
114 114
    @Override
115 115
    public void updateScripts() {
116 -
        LuaScriptThread mainThread = scriptContext.getMainThread();
116 +
        ILuaScriptThread mainThread = scriptContext.getMainThread();
117 117
        boolean mainThreadWasRunnable = mainThread.isRunnable();
118 118
119 119
        IScriptExceptionHandler defaultExceptionHandler = scriptContext.getDefaultExceptionHandler();

@@ -2,6 +2,7 @@
Loading
2 2
3 3
import java.io.File;
4 4
import java.io.IOException;
5 +
import java.util.Arrays;
5 6
import java.util.List;
6 7
7 8
import javax.annotation.Nullable;
@@ -16,17 +17,18 @@
Loading
16 17
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Files;
17 18
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter;
18 19
import com.badlogic.gdx.graphics.glutils.HdpiMode;
19 -
import com.google.common.collect.ImmutableList;
20 20
21 21
import joptsimple.OptionException;
22 22
import joptsimple.OptionParser;
23 23
import joptsimple.OptionSet;
24 +
import nl.weeaboo.common.Checks;
24 25
import nl.weeaboo.filesystem.IWritableFileSystem;
25 26
import nl.weeaboo.prefsstore.Preference;
26 27
import nl.weeaboo.vn.core.InitException;
27 28
import nl.weeaboo.vn.core.NovelPrefs;
28 29
import nl.weeaboo.vn.desktop.debug.NvlistDebugLauncher;
29 30
import nl.weeaboo.vn.gdx.res.DesktopGdxFileSystem;
31 +
import nl.weeaboo.vn.gdx.res.GdxFileSystem;
30 32
import nl.weeaboo.vn.impl.InitConfig;
31 33
import nl.weeaboo.vn.impl.Launcher;
32 34
import nl.weeaboo.vn.impl.core.NovelPrefsStore;
@@ -34,14 +36,22 @@
Loading
34 36
/**
35 37
 * Main entrypoint for desktop operating systems (Windows, Mac, Linux).
36 38
 */
37 -
public final class DesktopLauncher {
39 +
public final class DesktopLauncher extends Launcher {
38 40
39 41
    private static final Logger LOG = LoggerFactory.getLogger(DesktopLauncher.class);
40 42
41 -
    private final ImmutableList<String> args;
43 +
    private final GdxFileSystem resourceFileSystem;
42 44
43 -
    public DesktopLauncher(String[] args) {
44 -
        this.args = ImmutableList.copyOf(args);
45 +
    private @Nullable NvlistDebugLauncher debugLauncher;
46 +
47 +
    DesktopLauncher() {
48 +
        this(openResourceFileSystem(new File(".")), new DesktopOutputFileSystem(FileType.Local, "save/"));
49 +
    }
50 +
51 +
    DesktopLauncher(GdxFileSystem resourceFileSystem, IWritableFileSystem outputFileSystem) {
52 +
        super(resourceFileSystem, outputFileSystem);
53 +
54 +
        this.resourceFileSystem = Checks.checkNotNull(resourceFileSystem);
45 55
    }
46 56
47 57
    /**
@@ -51,7 +61,7 @@
Loading
51 61
        try {
52 62
            InitConfig.init();
53 63
54 -
            new DesktopLauncher(args).start();
64 +
            new DesktopLauncher().start(args);
55 65
        } catch (Exception e) {
56 66
            LOG.error("Fatal error during init", e);
57 67
            System.exit(1);
@@ -61,56 +71,13 @@
Loading
61 71
    /**
62 72
     * @throws InitException If a fatal error occurs during initialization.
63 73
     */
64 -
    public void start() throws InitException {
65 -
        DesktopGdxFileSystem gdxFileSystem = openResourceFileSystem(new File("."));
66 -
        IWritableFileSystem outputFileSystem = new DesktopOutputFileSystem(FileType.Local, "save/");
67 -
68 -
        final Launcher launcher = new Launcher(gdxFileSystem, outputFileSystem) {
69 -
70 -
            private @Nullable NvlistDebugLauncher debugLauncher;
71 -
72 -
            @Override
73 -
            public void create() {
74 -
                DesktopGraphicsUtil.setWindowIcon(gdxFileSystem);
75 -
                NovelPrefsStore prefs = loadPreferences();
76 -
                DesktopGraphicsUtil.limitInitialWindowSize(Gdx.graphics);
77 -
78 -
                if (prefs.get(NovelPrefs.DEBUG)) {
79 -
                    debugLauncher = NvlistDebugLauncher.launch(prefs.get(NovelPrefs.DEBUG_ADAPTER_PORT),
80 -
                            Gdx.app::postRunnable);
81 -
                }
82 -
83 -
                super.create();
84 -
85 -
                if (prefs.get(NovelPrefs.FULLSCREEN) && !prefs.get(NovelPrefs.DEBUG)) {
86 -
                    /*
87 -
                     * If in debug mode, never start full-screen. Full-screen is annoying when you need to use
88 -
                     * a bunch of other windows/programs at the same time.
89 -
                     *
90 -
                     * Must activate fullscreen mode after creating the window, or else the window is created
91 -
                     * without window decorations.
92 -
                     */
93 -
                    Gdx.graphics.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
94 -
                }
95 -
            }
96 -
97 -
            @Override
98 -
            public void dispose() {
99 -
                super.dispose();
100 -
101 -
                if (debugLauncher != null) {
102 -
                    debugLauncher.close();
103 -
                }
104 -
            }
105 -
        };
74 +
    public void start(String[] args) throws InitException {
75 +
        NovelPrefsStore prefs = loadPreferences();
76 +
        handleCommandlineOptions(prefs, args);
106 77
107 -
        NovelPrefsStore prefs = launcher.loadPreferences();
108 -
        handleCommandlineOptions(prefs);
109 -
110 -
        Lwjgl3ApplicationConfiguration config = createConfig(launcher, prefs);
111 78
        // Note: The Lwjgl3Application constructor contains an infinite loop
112 79
        @SuppressWarnings("unused")
113 -
        Lwjgl3Application app = new Lwjgl3Application(launcher, config) {
80 +
        Lwjgl3Application app = new Lwjgl3Application(this, createConfig(prefs)) {
114 81
115 82
        };
116 83
    }
@@ -125,7 +92,43 @@
Loading
125 92
        return new DesktopGdxFileSystem(new File(projectFolder, "res"));
126 93
    }
127 94
128 -
    private Lwjgl3ApplicationConfiguration createConfig(Launcher launcher, NovelPrefsStore prefs) {
95 +
    @Override
96 +
    public void create() {
97 +
        DesktopGraphicsUtil.setWindowIcon(resourceFileSystem);
98 +
99 +
        NovelPrefsStore prefs = loadPreferences();
100 +
        DesktopGraphicsUtil.limitInitialWindowSize(Gdx.graphics);
101 +
102 +
        if (prefs.get(NovelPrefs.DEBUG)) {
103 +
            debugLauncher = NvlistDebugLauncher.launch(prefs.get(NovelPrefs.DEBUG_ADAPTER_PORT),
104 +
                    Gdx.app::postRunnable);
105 +
        }
106 +
107 +
        super.create();
108 +
109 +
        if (prefs.get(NovelPrefs.FULLSCREEN) && !prefs.get(NovelPrefs.DEBUG)) {
110 +
            /*
111 +
             * If in debug mode, never start full-screen. Full-screen is annoying when you need to use
112 +
             * a bunch of other windows/programs at the same time.
113 +
             *
114 +
             * Must activate fullscreen mode after creating the window, or else the window is created
115 +
             * without window decorations.
116 +
             */
117 +
            Gdx.graphics.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
118 +
        }
119 +
    }
120 +
121 +
    @Override
122 +
    public void dispose() {
123 +
        super.dispose();
124 +
125 +
        if (debugLauncher != null) {
126 +
            debugLauncher.close();
127 +
            debugLauncher = null;
128 +
        }
129 +
    }
130 +
131 +
    Lwjgl3ApplicationConfiguration createConfig(NovelPrefsStore prefs) {
129 132
        Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
130 133
        config.useVsync(false);
131 134
@@ -141,7 +144,7 @@
Loading
141 144
        config.setWindowListener(new Lwjgl3WindowAdapter() {
142 145
            @Override
143 146
            public boolean closeRequested() {
144 -
                return launcher.onCloseRequested();
147 +
                return onCloseRequested();
145 148
            }
146 149
        });
147 150
@@ -156,8 +159,8 @@
Loading
156 159
        return title;
157 160
    }
158 161
159 -
    private void handleCommandlineOptions(NovelPrefsStore prefs) throws InitException {
160 -
        LOG.info("Commandline args: {}", args);
162 +
    void handleCommandlineOptions(NovelPrefsStore prefs, String[] args) throws InitException {
163 +
        LOG.info("Commandline args: {}", Arrays.asList(args));
161 164
162 165
        List<Preference<?>> declaredPrefs = NovelPrefsStore.getDeclaredPrefs(NovelPrefs.class);
163 166
@@ -168,7 +171,7 @@
Loading
168 171
169 172
        OptionSet options;
170 173
        try {
171 -
            options = optionParser.parse(args.toArray(new String[0]));
174 +
            options = optionParser.parse(args);
172 175
        } catch (OptionException oe) {
173 176
            try {
174 177
                optionParser.printHelpOn(System.out);

@@ -22,8 +22,8 @@
Loading
22 22
23 23
import nl.weeaboo.common.Dim;
24 24
import nl.weeaboo.filesystem.FilePath;
25 -
import nl.weeaboo.filesystem.FileSystemUtil;
26 25
import nl.weeaboo.filesystem.IFileSystem;
26 +
import nl.weeaboo.vn.gdx.graphics.PixmapLoader;
27 27
import nl.weeaboo.vn.gdx.graphics.PixmapUtil;
28 28
29 29
final class DesktopGraphicsUtil {
@@ -41,10 +41,8 @@
Loading
41 41
        try {
42 42
            FilePath path = FilePath.of("icon.png");
43 43
            try {
44 -
                byte[] bytes = FileSystemUtil.readBytes(fileSystem, path);
44 +
                Pixmap fullSize = PixmapLoader.load(fileSystem, path);
45 45
46 -
                LOG.info("Loading icon: {}", path);
47 -
                Pixmap fullSize = new Pixmap(bytes, 0, bytes.length);
48 46
                /*
49 47
                 * Convert to RGBA8888 (libGDX will do this later anyway, doing it now makes resize behavior
50 48
                 * more predictable)
@@ -65,7 +63,7 @@
Loading
65 63
            } catch (FileNotFoundException fnfe) {
66 64
                // File doesn't exist
67 65
            } catch (IOException ioe) {
68 -
                LOG.warn("Error loading icon: {}", path, ioe);
66 +
                LOG.warn("Error loading {}", path, ioe);
69 67
            }
70 68
71 69
            window.setIcon(Iterables.toArray(pixmaps, Pixmap.class));

@@ -68,7 +68,7 @@
Loading
68 68
     *
69 69
     * @see LuaThread#setPersistent(boolean)
70 70
     */
71 -
    public static LuaScriptThread createPersistentThread(LuaRunState runState) {
71 +
    public static ILuaScriptThread createPersistentThread(LuaRunState runState) {
72 72
        LuaThread thread = runState.newThread();
73 73
        thread.setPersistent(true);
74 74
        return new LuaScriptThread(thread);
@@ -123,7 +123,7 @@
Loading
123 123
            throws IOException, ScriptException {
124 124
125 125
        LuaScriptContext scriptContext = getScriptContext(mainContext);
126 -
        LuaScriptThread mainThread = scriptContext.getMainThread();
126 +
        ILuaScriptThread mainThread = scriptContext.getMainThread();
127 127
128 128
        IContext oldContext = ContextUtil.setCurrentContext(mainContext);
129 129
        try {
@@ -188,7 +188,7 @@
Loading
188 188
     * @throws ScriptException If the Lua code can't be parsed, or throws an exception.
189 189
     * @see IScriptLoader#loadScript(IScriptThread, FilePath)
190 190
     */
191 -
    public static String eval(IContextManager contextManager, LuaScriptThread thread, String luaCode)
191 +
    public static String eval(IContextManager contextManager, ILuaScriptThread thread, String luaCode)
192 192
            throws ScriptException {
193 193
194 194
        Varargs result;

@@ -29,7 +29,7 @@
Loading
29 29
/**
30 30
 * Default implementation of {@link IScriptThread}.
31 31
 */
32 -
public class LuaScriptThread implements IScriptThread {
32 +
class LuaScriptThread implements ILuaScriptThread {
33 33
34 34
    private static final long serialVersionUID = LuaImpl.serialVersionUID;
35 35
@@ -51,14 +51,12 @@
Loading
51 51
        return threadRef.get().isDead();
52 52
    }
53 53
54 +
    @Override
54 55
    public int getThreadId() {
55 56
        return threadRef.get().getThreadId();
56 57
    }
57 58
58 -
    /**
59 -
     * Runs Lua code on this thread.
60 -
     * @throws ScriptException If the Lua code can't be parsed, or throws an exception.
61 -
     */
59 +
    @Override
62 60
    public Varargs eval(String code) throws ScriptException {
63 61
        LuaThread thread = threadRef.get();
64 62
@@ -70,10 +68,7 @@
Loading
70 68
        }
71 69
    }
72 70
73 -
    /**
74 -
     * Calls a Lua function on this thread.
75 -
     * @throws ScriptException If the function doesn't exist, or the Lua code throws an exception.
76 -
     */
71 +
    @Override
77 72
    public void call(String funcName, Object... args) throws ScriptException {
78 73
        LuaThread thread = threadRef.get();
79 74
@@ -86,20 +81,14 @@
Loading
86 81
        }
87 82
    }
88 83
89 -
    /**
90 -
     * Calls a Lua function on this thread.
91 -
     * @throws ScriptException If the Lua function throws an exception.
92 -
     */
84 +
    @Override
93 85
    public void call(LuaScriptFunction func) throws ScriptException {
94 86
        LuaThread thread = threadRef.get();
95 87
96 88
        func.call(thread);
97 89
    }
98 90
99 -
    /**
100 -
     * Calls a Lua function on this thread.
101 -
     * @throws ScriptException If the Lua function throws an exception.
102 -
     */
91 +
    @Override
103 92
    public void call(LuaClosure func) throws ScriptException {
104 93
        LuaThread thread = threadRef.get();
105 94
@@ -144,10 +133,12 @@
Loading
144 133
        return getName();
145 134
    }
146 135
136 +
    @Override
147 137
    public @Nullable LuaStackTraceElement stackTraceElem(int offset) {
148 138
        return DebugTrace.stackTraceElem(threadRef.get(), offset);
149 139
    }
150 140
141 +
    @Override
151 142
    public List<LuaStackTraceElement> stackTrace() {
152 143
        return DebugTrace.stackTrace(threadRef.get());
153 144
    }
@@ -173,6 +164,7 @@
Loading
173 164
        paused = false;
174 165
    }
175 166
167 +
    @Override
176 168
    public void installHook(ILuaDebugHook callback) {
177 169
        LuaTable globals = LuaRunState.getCurrent().getGlobalEnvironment();
178 170
        Varargs args = LuaValue.varargsOf(threadRef.get(), new DebugHook(callback), LuaString.valueOf("crl"));
@@ -191,19 +183,10 @@
Loading
191 183
192 184
        @Override
193 185
        public LuaValue call(LuaValue eventName, LuaValue lineNumber) {
194 -
            callback.onEvent(eventName.tojstring(), lineNumber.optint(0));
186 +
            callback.onEvent(LuaDebugEvent.of(eventName.tojstring()), lineNumber.optint(0));
195 187
            return LuaConstants.NONE;
196 188
        }
197 189
198 190
    }
199 191
200 -
    /**
201 -
     * Lua debug library callback.
202 -
     */
203 -
    public interface ILuaDebugHook {
204 -
205 -
        void onEvent(String eventName, int lineNumber);
206 -
207 -
    }
208 -
209 192
}

@@ -36,9 +36,9 @@
Loading
36 36
    private final LuaScriptEnv scriptEnv;
37 37
    private final LuaTable contextGlobals;
38 38
    private final IScriptEventDispatcher eventDispatcher;
39 -
    private final LuaScriptThread mainThread;
39 +
    private final ILuaScriptThread mainThread;
40 40
41 -
    private final DestructibleElemList<LuaScriptThread> threads = new DestructibleElemList<>();
41 +
    private final DestructibleElemList<ILuaScriptThread> threads = new DestructibleElemList<>();
42 42
43 43
    public LuaScriptContext(LuaScriptEnv scriptEnv) {
44 44
        this.scriptEnv = Checks.checkNotNull(scriptEnv);
@@ -83,7 +83,7 @@
Loading
83 83
    public IScriptThread createThread(IScriptFunction func) throws ScriptException {
84 84
        LuaScriptFunction luaFunc = (LuaScriptFunction)func;
85 85
86 -
        LuaScriptThread thread = luaFunc.callInNewThread();
86 +
        ILuaScriptThread thread = luaFunc.callInNewThread();
87 87
        threads.add(thread);
88 88
        return thread;
89 89
    }
@@ -107,12 +107,12 @@
Loading
107 107
    }
108 108
109 109
    @Override
110 -
    public LuaScriptThread getMainThread() {
110 +
    public ILuaScriptThread getMainThread() {
111 111
        return mainThread;
112 112
    }
113 113
114 114
    @Override
115 -
    public Collection<LuaScriptThread> getThreads() {
115 +
    public Collection<ILuaScriptThread> getThreads() {
116 116
        return threads.getSnapshot();
117 117
    }
118 118
@@ -153,7 +153,7 @@
Loading
153 153
    }
154 154
155 155
    private void runThreads(IContext context, IScriptExceptionHandler exceptionHandler) {
156 -
        for (LuaScriptThread thread : threads) {
156 +
        for (ILuaScriptThread thread : threads) {
157 157
            if (!context.isActive()) {
158 158
                break;
159 159
            }

@@ -1,6 +1,5 @@
Loading
1 1
package nl.weeaboo.vn.desktop.debug;
2 2
3 -
import java.util.Collection;
4 3
import java.util.Collections;
5 4
import java.util.HashMap;
6 5
import java.util.Iterator;
@@ -19,10 +18,8 @@
Loading
19 18
20 19
import nl.weeaboo.vn.core.IContext;
21 20
import nl.weeaboo.vn.core.IContextManager;
22 -
import nl.weeaboo.vn.core.INovel;
23 -
import nl.weeaboo.vn.impl.script.lua.LuaScriptThread;
21 +
import nl.weeaboo.vn.impl.script.lua.ILuaScriptThread;
24 22
import nl.weeaboo.vn.script.IScriptContext;
25 -
import nl.weeaboo.vn.script.IScriptThread;
26 23
27 24
final class ActiveThreads implements Iterable<DebugThread> {
28 25
@@ -37,7 +34,7 @@
Loading
37 34
        this.breakpoints = Objects.requireNonNull(breakpoints);
38 35
    }
39 36
40 -
    public void update(INovel novel, IDebugProtocolClient peer) {
37 +
    public void update(IContextManager contextManager, IDebugProtocolClient peer) {
41 38
        // Remove dead threads
42 39
        Iterator<DebugThread> itr = threadsById.values().iterator();
43 40
        while (itr.hasNext()) {
@@ -55,13 +52,11 @@
Loading
55 52
        }
56 53
57 54
        // Update existing threads, detect new threads
58 -
        IContextManager contextManager = novel.getEnv().getContextManager();
59 55
        IContext primaryContext = contextManager.getPrimaryContext();
60 56
        for (IContext context : contextManager.getContexts()) {
61 57
            IScriptContext scriptContext = context.getScriptContext();
62 -
            Collection<? extends IScriptThread> threads = scriptContext.getThreads();
63 -
            for (LuaScriptThread thread : Iterables.filter(threads, LuaScriptThread.class)) {
64 -
                int threadId = DebugThread.getThreadId(thread);
58 +
            for (ILuaScriptThread thread : Iterables.filter(scriptContext.getThreads(), ILuaScriptThread.class)) {
59 +
                int threadId = thread.getThreadId();
65 60
66 61
                DebugThread debugThread = threadsById.get(threadId);
67 62
                if (debugThread == null) {
@@ -102,7 +97,8 @@
Loading
102 97
        if (frameId == null) {
103 98
            return primaryThread;
104 99
        } else {
105 -
            return primaryThread;
100 +
            LOG.warn("Unable to find thread with frame ID {}", frameId);
101 +
            return null;
106 102
        }
107 103
    }
108 104

@@ -0,0 +1,33 @@
Loading
1 +
package nl.weeaboo.vn.impl.script.lua;
2 +
3 +
/**
4 +
 * Lua debug event type.
5 +
 *
6 +
 * @see ILuaDebugHook
7 +
 */
8 +
public enum LuaDebugEvent {
9 +
    UNKNOWN,
10 +
    CALL,
11 +
    RETURN,
12 +
    TAIL_RETURN,
13 +
    LINE,
14 +
    COUNT;
15 +
16 +
    public static LuaDebugEvent of(String eventName) {
17 +
        switch (eventName) {
18 +
        case "call":
19 +
            return CALL;
20 +
        case "return":
21 +
            return LuaDebugEvent.RETURN;
22 +
        case "tail return":
23 +
            return LuaDebugEvent.TAIL_RETURN;
24 +
        case "line":
25 +
            return LINE;
26 +
        case "count":
27 +
            return COUNT;
28 +
        default:
29 +
            return UNKNOWN;
30 +
        }
31 +
    }
32 +
33 +
}

@@ -110,7 +110,7 @@
Loading
110 110
    private void update() {
111 111
        INovel novel = getNovel();
112 112
        if (novel != null) {
113 -
            activeThreads.update(novel, peer);
113 +
            activeThreads.update(novel.getEnv().getContextManager(), peer);
114 114
        }
115 115
    }
116 116
@@ -271,7 +271,7 @@
Loading
271 271
272 272
            IContextManager contextManager = novel.getEnv().getContextManager();
273 273
            DebugThread debugThread = activeThreads.findByFrameId(args.getFrameId());
274 -
            Preconditions.checkNotNull(novel, "NVList isn't active");
274 +
            Preconditions.checkNotNull(debugThread, "Unable to find thread");
275 275
276 276
            EvaluateResponse response = new EvaluateResponse();
277 277
            try {

@@ -177,7 +177,7 @@
Loading
177 177
178 178
        try {
179 179
            String result = LuaScriptUtil.eval(contextManager,
180 -
                    (LuaScriptThread)context.getScriptContext().getMainThread(), luaCode);
180 +
                    (ILuaScriptThread)context.getScriptContext().getMainThread(), luaCode);
181 181
            append("> " + result);
182 182
        } catch (ScriptException e) {
183 183
            LOG.info("Error during eval", e);

@@ -13,30 +13,27 @@
Loading
13 13
import org.eclipse.lsp4j.debug.services.IDebugProtocolClient;
14 14
15 15
import nl.weeaboo.lua2.vm.LuaStackTraceElement;
16 -
import nl.weeaboo.vn.impl.script.lua.LuaScriptThread;
17 -
import nl.weeaboo.vn.impl.script.lua.LuaScriptThread.ILuaDebugHook;
16 +
import nl.weeaboo.vn.impl.script.lua.ILuaDebugHook;
17 +
import nl.weeaboo.vn.impl.script.lua.ILuaScriptThread;
18 +
import nl.weeaboo.vn.impl.script.lua.LuaDebugEvent;
18 19
19 20
final class DebugThread {
20 21
21 -
    private final LuaScriptThread thread;
22 +
    private final ILuaScriptThread thread;
22 23
    private final IDebugProtocolClient peer;
23 24
24 25
    private @Nullable EStepMode stepMode;
25 26
26 -
    DebugThread(LuaScriptThread thread, IDebugProtocolClient peer) {
27 +
    DebugThread(ILuaScriptThread thread, IDebugProtocolClient peer) {
27 28
        this.thread = Objects.requireNonNull(thread);
28 29
        this.peer = Objects.requireNonNull(peer);
29 30
    }
30 31
31 -
    static int getThreadId(LuaScriptThread thread) {
32 -
        return System.identityHashCode(thread);
33 -
    }
34 -
35 32
    int getThreadId() {
36 33
        return thread.getThreadId();
37 34
    }
38 35
39 -
    LuaScriptThread getThread() {
36 +
    ILuaScriptThread getThread() {
40 37
        return thread;
41 38
    }
42 39
@@ -122,29 +119,29 @@
Loading
122 119
        }
123 120
124 121
        @Override
125 -
        public void onEvent(String eventName, int lineNumber) {
122 +
        public void onEvent(LuaDebugEvent event, int lineNumber) {
126 123
            if (stepMode != null) {
127 124
                switch (stepMode) {
128 125
                case IN:
129 -
                    if (eventName.endsWith("call")) {
126 +
                    if (event == LuaDebugEvent.CALL) {
130 127
                        stepHit();
131 128
                    }
132 129
                    break;
133 130
                case OUT:
134 -
                    if (eventName.equals("return")) {
131 +
                    if (event == LuaDebugEvent.RETURN || event == LuaDebugEvent.TAIL_RETURN) {
135 132
                        // Pausing during a "tail return" seems to cause stack corruption (this is a bug)
136 133
                        stepHit();
137 134
                    }
138 135
                    break;
139 136
                case NEXT:
140 137
                    // Ignore line events in nested function calls
141 -
                    if (eventName.endsWith("call")) {
138 +
                    if (event == LuaDebugEvent.CALL) {
142 139
                        depth++;
143 -
                    } else if (eventName.endsWith("return")) {
140 +
                    } else if (event == LuaDebugEvent.RETURN) {
144 141
                        depth--;
145 142
                    }
146 143
147 -
                    if (depth <= 0 && "line".equals(eventName)) {
144 +
                    if (depth <= 0 && event == LuaDebugEvent.LINE) {
148 145
                        stepHit();
149 146
                    }
150 147
                    break;

@@ -38,7 +38,7 @@
Loading
38 38
        }
39 39
    }
40 40
41 -
    LuaScriptThread callInNewThread() throws ScriptException {
41 +
    ILuaScriptThread callInNewThread() throws ScriptException {
42 42
        LuaRunState runState = LuaImpl.getRunState();
43 43
        LuaThread thread = runState.newThread(func, args);
44 44
        return new LuaScriptThread(thread);
Files Complexity Coverage
api/src/main/java/nl/weeaboo/vn 91.53% 96.76%
buildtools/src/main/java/nl/weeaboo/vn/buildtools 81.13% 87.46%
core/src/main/java/nl/weeaboo/vn 82.38% 86.59%
desktop/src/main/java/nl/weeaboo/vn/desktop 46.38% 51.56%
Project Totals (384 files) 82.05% 86.11%
1
codecov:
2
  status:
3
    project: yes
4
    patch: no
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading