/* ** Get a global object. */ lua_Object lua_getglobal (char *name) { adjustC(0); getglobal(luaI_findsymbolbyname(name)); CLS_current.base++; /* incorporate object in the stack */ return Ref(top-1); }
/* ** API: receives on the stack the table and the index. ** returns the value. */ lua_Object lua_getsubscript (void) { adjustC(2); pushsubscript(); CLS_current.base++; /* incorporate object in the stack */ return (Ref(top-1)); }
/* ** API: creates a new table */ lua_Object lua_createtable (void) { adjustC(0); avalue(top) = lua_createarray(0); tag(top) = LUA_T_ARRAY; incr_top; CLS_current.base++; /* incorporate object in the stack */ return Ref(top-1); }
int luaI_dorun (TFunc *tf) { int status; adjustC(1); /* one slot for the pseudo-function */ stack[CLS_current.base].tag = LUA_T_FUNCTION; stack[CLS_current.base].value.tf = tf; status = do_protectedrun(MULT_RET); return status; }
lua_Object lua_getref (int ref) { Object *o = luaI_getref(ref); if (o == NULL) return LUA_NOOBJECT; adjustC(0); luaI_pushobject(o); CLS_current.base++; /* incorporate object in the stack */ return Ref(top-1); }
/* ** API: set a function as a fallback */ lua_Object lua_setfallback (char *name, lua_CFunction fallback) { adjustC(1); /* one slot for the pseudo-function */ stack[CLS_current.base].tag = LUA_T_CFUNCTION; stack[CLS_current.base].value.f = luaI_setfallback; lua_pushstring(name); lua_pushcfunction(fallback); if (do_protectedrun(1) == 0) return (Ref(top-1)); else return LUA_NOOBJECT; }
int lua_setlocal (lua_Function func, int local_number) { Object *f = Address(func); char *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); adjustC(1); --top; if (name) { /* if "name", there must be a LUA_T_LINE */ /* therefore, f+2 points to function base */ *((f+2)+(local_number-1)) = *top; return 1; } else return 0; }
int lua_domain (void) { TFunc tf; int status; jmp_buf myErrorJmp; jmp_buf *oldErr = errorJmp; errorJmp = &myErrorJmp; luaI_initTFunc(&tf); if (setjmp(myErrorJmp) == 0) { lua_parse(&tf); status = 0; } else { adjustC(0); /* erase extra slot */ status = 1; } if (status == 0) status = luaI_dorun(&tf); errorJmp = oldErr; luaI_free(tf.code); return status; }
static int do_protectedmain (void) { TFunc tf; int status; jmp_buf myErrorJmp; jmp_buf *oldErr = errorJmp; errorJmp = &myErrorJmp; luaI_initTFunc(&tf); tf.fileName = lua_parsedfile; if (setjmp(myErrorJmp) == 0) { lua_parse(&tf); status = luaI_dorun(&tf); } else { status = 1; adjustC(0); /* erase extra slot */ } errorJmp = oldErr; luaI_free(tf.code); return status; }
/* ** Store top of the stack at a global variable array field. */ void lua_storeglobal (char *name) { Word n = luaI_findsymbolbyname(name); adjustC(1); s_object(n) = *(--top); }
int lua_ref (int lock) { adjustC(1); return luaI_ref(--top, lock); }
/* ** API: receives on the stack the table, the index, and the new value. */ void lua_storesubscript (void) { adjustC(3); storesubscript(); }
/* ** API: ends a block */ void lua_endblock (void) { --numCblocks; CLS_current = Cblocks[numCblocks]; adjustC(0); }