summaryrefslogtreecommitdiff
path: root/src/func.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>1995-11-28 12:00:00 +0000
committerrepogen <>1995-11-28 12:00:00 +0000
commit71754d2f6423fb9b6e87658e58bafc5470d53f65 (patch)
treec704e97b80e52a52d3152738941bb4c8ca676b97 /src/func.c
parenta8b6ba0954edb9e0e669e1f451b9a8f145ce5166 (diff)
downloadlua-github-2.2.tar.gz
Lua 2.22.2
Diffstat (limited to 'src/func.c')
-rw-r--r--src/func.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/func.c b/src/func.c
new file mode 100644
index 00000000..2982f661
--- /dev/null
+++ b/src/func.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+
+#include "luadebug.h"
+#include "table.h"
+#include "mem.h"
+#include "func.h"
+#include "opcode.h"
+
+static TFunc *function_root = NULL;
+
+
+/*
+** Insert function in list for GC
+*/
+void luaI_insertfunction (TFunc *f)
+{
+ lua_pack();
+ f->next = function_root;
+ function_root = f;
+ f->marked = 0;
+}
+
+
+/*
+** Free function
+*/
+static void freefunc (TFunc *f)
+{
+ luaI_free (f->code);
+ luaI_free (f);
+}
+
+/*
+** Garbage collection function.
+** This function traverse the function list freeing unindexed functions
+*/
+Long luaI_funccollector (void)
+{
+ TFunc *curr = function_root;
+ TFunc *prev = NULL;
+ Long counter = 0;
+ while (curr)
+ {
+ TFunc *next = curr->next;
+ if (!curr->marked)
+ {
+ if (prev == NULL)
+ function_root = next;
+ else
+ prev->next = next;
+ freefunc (curr);
+ ++counter;
+ }
+ else
+ {
+ curr->marked = 0;
+ prev = curr;
+ }
+ curr = next;
+ }
+ return counter;
+}
+
+
+void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
+{
+ Object *f = luaI_Address(func);
+ if (f->tag == LUA_T_MARK || f->tag == LUA_T_FUNCTION)
+ {
+ *filename = f->value.tf->fileName;
+ *linedefined = f->value.tf->lineDefined;
+ }
+ else if (f->tag == LUA_T_CMARK || f->tag == LUA_T_CFUNCTION)
+ {
+ *filename = "(C)";
+ *linedefined = -1;
+ }
+}
+