@@ -7,7 +7,7 @@
# Your platform. See PLATS for possible values.
PLAT= none

CC= gcc
CC= gcc -DLUA_USE_APICHECK
CFLAGS= -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
@@ -29,6 +29,7 @@
#include "lundump.h"
#include "lvm.h"

void sztrace(char *);


const char lua_ident[] =
@@ -211,7 +212,7 @@ LUA_API void lua_replace (lua_State *L, int idx) {
api_checkvalidindex(L, o);
if (idx == LUA_ENVIRONINDEX) {
Closure *func = curr_func(L);
api_check(L, ttistable(L->top - 1));
api_check(L, ttistable(L->top - 1));
func->c.env = hvalue(L->top - 1);
luaC_barrier(L, func, L->top - 1);
}
@@ -644,13 +645,36 @@ LUA_API void lua_getfenv (lua_State *L, int idx) {

LUA_API void lua_settable (lua_State *L, int idx) {
StkId t;

sztrace("0057.1.0030.1.0072.0140.0010 -- lua_settable BEGIN");

lua_lock(L);

sztrace("0057.1.0030.1.0072.0140.0020");

api_checknelems(L, 2);

sztrace("0057.1.0030.1.0072.0140.0030");

t = index2adr(L, idx);

sztrace("0057.1.0030.1.0072.0140.0040");

api_checkvalidindex(L, t);

sztrace("0057.1.0030.1.0072.0140.0050");

luaV_settable(L, t, L->top - 2, L->top - 1);

sztrace("0057.1.0030.1.0072.0140.0060");

L->top -= 2; /* pop index and value */

sztrace("0057.1.0030.1.0072.0140.0070");

lua_unlock(L);

sztrace("0057.1.0030.1.0072.0140.0080 -- lua_settable END");
}


@@ -771,7 +795,7 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {

#define checkresults(L,na,nr) \
api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)))


LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
StkId func;
@@ -239,32 +239,75 @@ static int libsize (const luaL_Reg *l) {
}


void sztrace(char *);

LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup) {
char buf[4096];

sztrace("0057.1.0030.1.0010 -- luaI_openlib BEGIN");

if (libname) {
sztrace("0057.1.0030.1.0020");
int size = libsize(l);
sztrace("0057.1.0030.1.0030");
/* check whether lib already exists */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
sztrace("0057.1.0030.1.0040");
lua_getfield(L, -1, libname); /* get _LOADED[libname] */
sztrace("0057.1.0030.1.0050");
if (!lua_istable(L, -1)) { /* not found? */
sztrace("0057.1.0030.1.0060");
lua_pop(L, 1); /* remove previous result */
sztrace("0057.1.0030.1.0070");

sprintf(
buf,
"0057.1.0030.1.0071 L %p libname %s size %d globalsindex %d",
L, libname, size, LUA_GLOBALSINDEX
);
sztrace(buf);

sztrace("0057.1.0030.1.0072");

/* try global variable (and create one if it does not exist) */
if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
{
sztrace("0057.1.0030.1.0080");
luaL_error(L, "name conflict for module " LUA_QS, libname);
sztrace("0057.1.0030.1.0090");
}
sztrace("0057.1.0030.1.0100");
lua_pushvalue(L, -1);
sztrace("0057.1.0030.1.0110");
lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
sztrace("0057.1.0030.1.0120");
}
sztrace("0057.1.0030.1.0130");
lua_remove(L, -2); /* remove _LOADED table */
sztrace("0057.1.0030.1.0140");
lua_insert(L, -(nup+1)); /* move library table to below upvalues */
sztrace("0057.1.0030.1.0150");
}
sztrace("0057.1.0030.1.0160");
for (; l->name; l++) {
int i;
sztrace("0057.1.0030.1.0170");
for (i=0; i<nup; i++) /* copy upvalues to the top */
{
sztrace("0057.1.0030.1.0180");
lua_pushvalue(L, -nup);
sztrace("0057.1.0030.1.0190");
}
sztrace("0057.1.0030.1.0200");
lua_pushcclosure(L, l->func, nup);
sztrace("0057.1.0030.1.0210");
lua_setfield(L, -(nup+2), l->name);
sztrace("0057.1.0030.1.0220");
}
sztrace("0057.1.0030.1.0230");
lua_pop(L, nup); /* remove upvalues */
sztrace("0057.1.0030.1.0240 -- luaI_openlib END");
}


@@ -357,26 +400,66 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
const char *fname, int szhint) {
const char *e;

sztrace("0057.1.0030.1.0072.0010 -- luaL_findtable BEGIN");

lua_pushvalue(L, idx);

sztrace("0057.1.0030.1.0072.0020");

do {

sztrace("0057.1.0030.1.0072.0030");

e = strchr(fname, '.');
if (e == NULL) e = fname + strlen(fname);

sztrace("0057.1.0030.1.0072.0040");

if (e == NULL)
{
sztrace("0057.1.0030.1.0072.0050");
e = fname + strlen(fname);
sztrace("0057.1.0030.1.0072.0060");
}

sztrace("0057.1.0030.1.0072.0070");

lua_pushlstring(L, fname, e - fname);

sztrace("0057.1.0030.1.0072.0080");

lua_rawget(L, -2);

sztrace("0057.1.0030.1.0072.0090");

if (lua_isnil(L, -1)) { /* no such field? */
sztrace("0057.1.0030.1.0072.0100");
lua_pop(L, 1); /* remove this nil */
sztrace("0057.1.0030.1.0072.0110");
lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
sztrace("0057.1.0030.1.0072.0120");
lua_pushlstring(L, fname, e - fname);
sztrace("0057.1.0030.1.0072.0130");
lua_pushvalue(L, -2);
sztrace("0057.1.0030.1.0072.0140");
lua_settable(L, -4); /* set new table into field */
sztrace("0057.1.0030.1.0072.0150");
}
else if (!lua_istable(L, -1)) { /* field has a non-table value? */
sztrace("0057.1.0030.1.0072.0160");
lua_pop(L, 2); /* remove table and value */
sztrace("0057.1.0030.1.0072.0170");
return fname; /* return problematic part of the name */
}
sztrace("0057.1.0030.1.0072.0180");
lua_remove(L, -2); /* remove previous table */
sztrace("0057.1.0030.1.0072.0190");
fname = e + 1;
sztrace("0057.1.0030.1.0072.0200");
} while (*e == '.');

sztrace("0057.1.0030.1.0072.0210 -- luaL_findtable END");

return NULL;
}

@@ -19,6 +19,7 @@
#include "lauxlib.h"
#include "lualib.h"

void sztrace(char *);



@@ -625,23 +626,91 @@ static void auxopen (lua_State *L, const char *name,

static void base_open (lua_State *L) {
/* set global _G */

char buf[4096];

sztrace("0057.1.0010 -- base_open BEGIN");

lua_pushvalue(L, LUA_GLOBALSINDEX);

sztrace("0057.1.0020");

sprintf(
buf,
"0057.1.0021 L %p top type %s globalsindex %d",
L, luaL_typename(L, -1), LUA_GLOBALSINDEX
);
sztrace(buf);

sztrace("0057.1.0022");

lua_setglobal(L, "_G");

sztrace("0057.1.0023");

lua_getglobal(L, "_G");

sztrace("0057.1.0024");

sprintf(buf, "0057.1.0025 L %p top type %s", L, luaL_typename(L, -1));
sztrace(buf);

sztrace("0057.1.0026");

lua_pop(L, 1);

sztrace("0057.1.0030");

/* open lib into global table */
luaL_register(L, "_G", base_funcs);

sztrace("0057.1.0040");

lua_pushliteral(L, LUA_VERSION);

sztrace("0057.1.0050");

lua_setglobal(L, "_VERSION"); /* set global _VERSION */

sztrace("0057.1.0060");

/* `ipairs' and `pairs' need auxliliary functions as upvalues */
auxopen(L, "ipairs", luaB_ipairs, ipairsaux);

sztrace("0057.1.0070");

auxopen(L, "pairs", luaB_pairs, luaB_next);

sztrace("0057.1.0080");

/* `newproxy' needs a weaktable as upvalue */
lua_createtable(L, 0, 1); /* new table `w' */

sztrace("0057.1.0090");

lua_pushvalue(L, -1); /* `w' will be its own metatable */

sztrace("0057.1.0100");

lua_setmetatable(L, -2);

sztrace("0057.1.0110");

lua_pushliteral(L, "kv");

sztrace("0057.1.0120");

lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */

sztrace("0057.1.0130");

lua_pushcclosure(L, luaB_newproxy, 1);

sztrace("0057.1.0140");

lua_setglobal(L, "newproxy"); /* set global `newproxy' */

sztrace("0057.1.0150 -- base_open END");
}


@@ -13,6 +13,7 @@
#include "lualib.h"
#include "lauxlib.h"

void sztrace(char *);

static const luaL_Reg lualibs[] = {
{"", luaopen_base},
@@ -28,11 +29,26 @@ static const luaL_Reg lualibs[] = {


LUALIB_API void luaL_openlibs (lua_State *L) {
sztrace("0051 -- luaL_openlibs BEGIN 1");
const luaL_Reg *lib = lualibs;
char buf[4096];
sztrace("0052");
for (; lib->func; lib++) {
sztrace("0053");
sprintf(
buf,
"0053.1 name %s L %p lib %p func %p",
lib->name, L, lib, lib->func
);
sztrace(buf);
sztrace("0054");
lua_pushcfunction(L, lib->func);
sztrace("0055");
lua_pushstring(L, lib->name);
sztrace("0056");
lua_call(L, 1, 0);
sztrace("0058");
}
sztrace("0059 -- luaL_openlibs BEGIN");
}