on master help sign in
[Lua] [sus] Fix intermittent Lua crashes (#93)

* extremely sus bugfix * add loop to lua_test.go, remove unnecessary test.lua in root * remove example goroutine comments, since this will always be called from a single OS thread

commit24a859a1b52b3c7ee7483f761b48541150160539 authorLee Fleming <102989413+LeeFlemingRepl@users.noreply.github.com> dateTue 21 Jun 2022, 09:50 (4 years ago) parent7d40edb
3 files changed+18−5
languages/lua/lua.c+2−5 languages/lua/lua_test.go+15 languages/lua/testdata/test.lua+1
languages/lua/lua.c+2−5
@@ -93,12 +93,9 @@ static void print_version(void) {
9393 l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
9494}
9595
96−static int getargs(lua_State *L, char **argv, int n) {
96+static int getargs(lua_State *L, char **argv, int n, int argc) {
9797 int narg;
9898 int i;
99− int argc = 0;
100− while (argv[argc])
101− argc++; /* count total number of arguments */
10299 narg = argc - (n + 1); /* number of arguments to the script */
103100 luaL_checkstack(L, narg + 3, "too many arguments to script");
104101 for (i = n + 1; i < argc; i++)
@@ -230,7 +227,7 @@ void dotty(lua_State *L) {
230227int handle_script(lua_State *L, char **argv, int n) {
231228 int status;
232229 const char *fname;
233− int narg = getargs(L, argv, n); /* collect arguments */
230+ int narg = getargs(L, argv, n, 1); /* collect arguments */
234231 lua_setglobal(L, "arg");
235232 fname = argv[n];
236233 if (strcmp(fname, "-") == 0 && strcmp(argv[n - 1], "--") != 0)
languages/lua/lua_test.gonew file+15
@@ -0,0 +1,15 @@
1+package main
2+
3+import (
4+ "testing"
5+)
6+
7+// Mostly a debugging aid, not sure if it'll actually fail if something goes wrong
8+func TestLuaStuff(t *testing.T) {
9+ var lua Lua
10+ lua.Open()
11+ lua.Version()
12+ for i := 0; i < 100; i++ {
13+ lua.EvalFile("testdata/test.lua", make([]string, 0))
14+ }
15+}
languages/lua/testdata/test.luanew file+1
@@ -0,0 +1 @@
1+print("Hello, World!")