Commit bbeb09b6 authored by Terry Ellison's avatar Terry Ellison Committed by Marcel Stör
Browse files

Squashed updates do get Lua51 and Lua53 working (#3075)

-  Lots of minor but nasty bugfixes to get all tests to run clean
-  core lua and test suite fixes to allow luac -F to run cleanly against test suite
-  next tranch to get LFS working
-  luac.cross -a options plus fixes from feedback
-  UART fixes and lua.c merge
-  commit of wip prior to rebaselining against current dev
-  more tweaks
parent 99aba344
...@@ -109,7 +109,7 @@ ifneq (,$(findstring indows,$(OS))) ...@@ -109,7 +109,7 @@ ifneq (,$(findstring indows,$(OS)))
else else
# It is gcc, may be cygwin # It is gcc, may be cygwin
# Can we use -fdata-sections? # Can we use -fdata-sections?
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections -fpack-struct=4
AR = xtensa-lx106-elf-ar AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc CC = xtensa-lx106-elf-gcc
CXX = xtensa-lx106-elf-g++ CXX = xtensa-lx106-elf-g++
......
...@@ -15,6 +15,13 @@ TARGET = eagle ...@@ -15,6 +15,13 @@ TARGET = eagle
#FLAVOR = release #FLAVOR = release
FLAVOR = debug FLAVOR = debug
# Handle Lua Directory selector
ifeq ("$(LUA)","53")
LUA_DIR := lua53
else
LUA_DIR := lua
endif
ifndef PDIR # { ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin GEN_BINS= eagle.app.v6.bin
...@@ -34,15 +41,15 @@ SUBDIRS= \ ...@@ -34,15 +41,15 @@ SUBDIRS= \
mbedtls \ mbedtls \
platform \ platform \
libc \ libc \
lua \ $(LUA_DIR) \
lwip \ lwip \
smart \ smart \
modules \ modules \
spiffs \ spiffs \
net \ net \
fatfs \ fatfs \
esp-gdbstub \ esp-gdbstub \
pm \ pm \
uzlib \ uzlib \
$(OPT_SEL_MKTARGETS) $(OPT_SEL_MKTARGETS)
...@@ -65,7 +72,7 @@ COMPONENTS_eagle.app.v6 = \ ...@@ -65,7 +72,7 @@ COMPONENTS_eagle.app.v6 = \
driver/libdriver.a \ driver/libdriver.a \
platform/libplatform.a \ platform/libplatform.a \
libc/liblibc.a \ libc/liblibc.a \
lua/liblua.a \ $(LUA_DIR)/liblua.a \
lwip/liblwip.a \ lwip/liblwip.a \
smart/smart.a \ smart/smart.a \
spiffs/spiffs.a \ spiffs/spiffs.a \
...@@ -150,7 +157,7 @@ DDEFINES += \ ...@@ -150,7 +157,7 @@ DDEFINES += \
# #
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \ INCLUDES := -I $(PDIR)libc -I $(PDIR)$(LUA_DIR) -I $(PDIR)platform \
$(INCLUDES) -I $(PDIR) -I $(PDIR)include $(INCLUDES) -I $(PDIR) -I $(PDIR)include
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
......
...@@ -171,9 +171,20 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -171,9 +171,20 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{ {
char line[LUA_MAXINPUT+1]; char line[LUA_MAXINPUT+1];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload)) { if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload)) {
lua_State *L = lua_getstate();
int base = lua_gettop(L), n, status;
int l = strlen(line); int l = strlen(line);
line[l] = '\n'; line[l++] = '\n';
lua_input_string(line, l+1); /* compile and exec payload; any error or results will be left on the stack and printed */
/* TODO: consider returning output as result instead of printing */
luaL_dostring(L, line);
if ((n = lua_gettop(L) - base) > 0)
{
lua_getglobal(L, "print");
lua_insert(L, base);
lua_pcall(L, n, 0, 0);
lua_settop(L, base);
}
} }
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN); return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
} }
......
...@@ -173,7 +173,7 @@ i2c_master_setDC(uint16 id, uint8 SDA, uint8 SCL) ...@@ -173,7 +173,7 @@ i2c_master_setDC(uint16 id, uint8 SDA, uint8 SCL)
while(!(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1)) {}; //read SCL value until SCL goes high while(!(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1)) {}; //read SCL value until SCL goes high
}else{ }else{
// dummy read operation and empty CPU cycles to maintain equal times for low and high state // dummy read operation and empty CPU cycles to maintain equal times for low and high state
READ_PERI_REG(RTC_GPIO_IN_DATA) & 1; asm volatile("nop;nop;nop;nop;"); (void) (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); asm volatile("nop;nop;nop;nop;");
} }
} }
else{ else{
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include <stdint.h> #include <stdint.h>
#include "mem.h" #include "mem.h"
/**DEBUG**/extern void dbg_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
static void input_handler(platform_task_param_t flag, uint8 priority); static void input_handler(platform_task_param_t flag, uint8 priority);
static struct input_state { static struct input_state {
...@@ -63,7 +61,7 @@ static bool uart_getc(char *c){ ...@@ -63,7 +61,7 @@ static bool uart_getc(char *c){
** The ins.data check detects up the first task call which used to initialise ** The ins.data check detects up the first task call which used to initialise
** everything. ** everything.
*/ */
int lua_main (void); extern int lua_main (void);
static bool input_readline(void); static bool input_readline(void);
static void input_handler(platform_task_param_t flag, uint8 priority) { static void input_handler(platform_task_param_t flag, uint8 priority) {
...@@ -79,7 +77,7 @@ static void input_handler(platform_task_param_t flag, uint8 priority) { ...@@ -79,7 +77,7 @@ static void input_handler(platform_task_param_t flag, uint8 priority) {
/* /*
** The input state (ins) is private, so input_setup() exposes the necessary ** The input state (ins) is private, so input_setup() exposes the necessary
** access to public properties and is called in user_init() before the Lua ** access to public properties and is called in user_init() before the Lua
** enviroment is initialised. The second routine input_setup_receive() is ** enviroment is initialised. The second routine input_setup_receive() is
** called in lua.c after the Lua environment is available to bind the Lua ** called in lua.c after the Lua environment is available to bind the Lua
** input handler. Any UART input before this receive setup is ignored. ** input handler. Any UART input before this receive setup is ignored.
*/ */
...@@ -112,15 +110,15 @@ void input_setprompt (const char *prompt) { ...@@ -112,15 +110,15 @@ void input_setprompt (const char *prompt) {
} }
/* /*
** input_readline() is called from the input_handler() event routine which is ** input_readline() is called from the input_handler() event routine which is
** posted by the UART Rx ISR posts. This works in one of two modes depending on ** posted by the UART Rx ISR posts. This works in one of two modes depending on
** the bool ins.run_input. ** the bool ins.run_input.
** - TRUE: it clears the UART FIFO up to EOL, doing any callback and sending ** - TRUE: it clears the UART FIFO up to EOL, doing any callback and sending
** the line to Lua. ** the line to Lua.
** - FALSE: it clears the UART FIFO doing callbacks according to the data_len / ** - FALSE: it clears the UART FIFO doing callbacks according to the data_len
** end_char break. ** or end_char break.
*/ */
void lua_input_string (const char *line, int len); extern void lua_input_string (const char *line, int len);
static bool input_readline(void) { static bool input_readline(void) {
char ch = NUL; char ch = NUL;
...@@ -182,9 +180,9 @@ static bool input_readline(void) { ...@@ -182,9 +180,9 @@ static bool input_readline(void) {
} else { } else {
while (uart_getc(&ch)) { while (uart_getc(&ch)) {
ins.data[ins.line_pos++] = ch; ins.data[ins.line_pos++] = ch;
if( ins.line_pos >= ins.len || if( ins.line_pos >= ins.len ||
(ins.data_len > 0 && ins.line_pos >= ins.data_len) || (ins.data_len >= 0 && ins.line_pos >= ins.data_len) ||
ch == ins.end_char ) { (ins.data_len < 0 && ch == ins.end_char )) {
ins.uart_cb(ins.data, ins.line_pos); ins.uart_cb(ins.data, ins.line_pos);
ins.line_pos = 0; ins.line_pos = 0;
} }
......
/* /*
* Software PWM using soft-interrupt timer1. * Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one. * Supports higher frequencies compared to Espressif provided one.
* *
* Nikolay Fiykov * Nikolay Fiykov
...@@ -204,7 +204,7 @@ void pwm2_setup_pin( ...@@ -204,7 +204,7 @@ void pwm2_setup_pin(
const uint32_t freqDivisor, const uint32_t freqDivisor,
const uint32_t resolution, const uint32_t resolution,
const uint32_t initDuty const uint32_t initDuty
) )
{ {
moduleData->setupData.pin[pin].pulseResolutions = resolution; moduleData->setupData.pin[pin].pulseResolutions = resolution;
moduleData->setupData.pin[pin].divisableFrequency = divisableFreq; moduleData->setupData.pin[pin].divisableFrequency = divisableFreq;
......
...@@ -188,16 +188,24 @@ uart0_tx_buffer(uint8 *buf, uint16 len) ...@@ -188,16 +188,24 @@ uart0_tx_buffer(uint8 *buf, uint16 len)
* FunctionName : uart0_sendStr * FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer * Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer * Parameters : uint8 *buf - point to send buffer
* uint16 len - buffer len
* Returns : * Returns :
*******************************************************************************/ *******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStr(const char *str) void ICACHE_FLASH_ATTR uart0_sendStr(const char *str) {
{
while(*str) while(*str)
{
// uart_tx_one_char(UART0, *str++);
uart0_putc(*str++); uart0_putc(*str++);
} }
/******************************************************************************
* FunctionName : uart0_sendStr
* Description : use uart0 to transfer buffer
* Parameters : uint8 *buf - point to send buffer
* size_t len - buffer len
* Returns :
*******************************************************************************/
void ICACHE_FLASH_ATTR uart0_sendStrn(const char *str, size_t len) {
size_t i;
for(i = 0; i < len; i++)
uart0_putc(*str++);
} }
/****************************************************************************** /******************************************************************************
......
/* /*
* Software PWM using soft-interrupt timer1. * Software PWM using soft-interrupt timer1.
* Supports higher frequencies compared to Espressif provided one. * Supports higher frequencies compared to Espressif provided one.
* *
* Nikolay Fiykov * Nikolay Fiykov
......
...@@ -115,6 +115,7 @@ void uart_init_task(os_signal_t sig_input, uint8 *flag_input); ...@@ -115,6 +115,7 @@ void uart_init_task(os_signal_t sig_input, uint8 *flag_input);
UartConfig uart_get_config(uint8 uart_no); UartConfig uart_get_config(uint8 uart_no);
void uart0_alt(uint8 on); void uart0_alt(uint8 on);
void uart0_sendStr(const char *str); void uart0_sendStr(const char *str);
void uart0_sendStrn(const char *str, size_t len);
void uart0_putc(const char c); void uart0_putc(const char c);
void uart0_tx_buffer(uint8 *buf, uint16 len); void uart0_tx_buffer(uint8 *buf, uint16 len);
void uart_setup(uint8 uart_no); void uart_setup(uint8 uart_no);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __MODULE_H__ #define __MODULE_H__
#include "user_modules.h" #include "user_modules.h"
#include "lrotable.h" #include "lnodemcu.h"
/* Registering a module within NodeMCU is really easy these days! /* Registering a module within NodeMCU is really easy these days!
* *
...@@ -38,23 +38,6 @@ ...@@ -38,23 +38,6 @@
#define MODULE_PASTE_(x,y) x##y #define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y) #define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)
#ifdef LUA_CROSS_COMPILER
#ifdef _MSC_VER
//on msvc it is necessary to go through more pre-processor hoops to get the
//section name built; string merging does not happen in the _declspecs.
//NOTE: linker magic is invoked via the magical '$' character. Caveat editor.
#define __TOKIFY(s) .rodata1$##s
#define __TOTOK(s) __TOKIFY(s)
#define __STRINGIFY(x) #x
#define __TOSTRING(x) __STRINGIFY(x)
#define __ROSECNAME(s) __TOSTRING(__TOTOK(s))
#define LOCK_IN_SECTION(s) __declspec ( allocate( __ROSECNAME(s) ) )
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".rodata1." #s)))
#endif
#else
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s)))
#endif
/* For the ROM table, we name the variable according to ( | denotes concat): /* For the ROM table, we name the variable according to ( | denotes concat):
* cfgname | _module_selected | LUA_USE_MODULES_##cfgname * cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* where the LUA_USE_MODULES_XYZ macro is first expanded to yield either * where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
...@@ -67,8 +50,8 @@ ...@@ -67,8 +50,8 @@
*/ */
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \ #define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(libs) \ const LOCK_IN_SECTION(libs) \
luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \ ROTable_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
const LOCK_IN_SECTION(rotable) \ const LOCK_IN_SECTION(rotable) \
luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \ ROTable_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {luaname, LRO_ROVAL(map ## _map)} = {luaname, LRO_ROVAL(map)}
#endif #endif
#ifndef _TASK_H_ #ifndef _TASK_H_
#define _TASK_H_ #define _TASK_H_
/* /*
** The task interface is now part of the core platform interface. ** The task interface is now part of the core platform interface.
** This header is preserved for backwards compatability only. ** This header is preserved for backwards compatability only.
*/ */
#include "platform.h" #include "platform.h"
#define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW #define TASK_PRIORITY_LOW PLATFORM_TASK_PRIORITY_LOW
#define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM #define TASK_PRIORITY_MEDIUM PLATFORM_TASK_PRIORITY_MEDIUM
#define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH #define TASK_PRIORITY_HIGH PLATFORM_TASK_PRIORITY_HIGH
#define task_post(priority,handle,param) platform_post(priority,handle,param) #define task_post(priority,handle,param) platform_post(priority,handle,param)
#define task_post_low(handle,param) platform_post_low(handle,param) #define task_post_low(handle,param) platform_post_low(handle,param)
......
...@@ -248,15 +248,15 @@ ...@@ -248,15 +248,15 @@
#define READLINE_INTERVAL 80 #define READLINE_INTERVAL 80
#define STRBUF_DEFAULT_INCREMENT 3 #define STRBUF_DEFAULT_INCREMENT 3
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback() #define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
#ifdef DEVELOPMENT_TOOLS #if defined(DEVELOPMENT_TOOLS) && defined(DEVELOPMENT_USE_GDB)
#if defined(LUA_CROSS_COMPILER) || !defined(DEVELOPMENT_USE_GDB) extern void LUA_DEBUG_HOOK (void);
#define lua_assert(x) ((x) ? (void) 0 : LUA_DEBUG_HOOK ())
#elif defined(DEVELOPMENT_TOOLS) && defined(LUA_CROSS_COMPILER)
extern void luaL_assertfail(const char *file, int line, const char *message); extern void luaL_assertfail(const char *file, int line, const char *message);
#define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x)) #define lua_assert(x) ((x) ? (void) 0 : luaL_assertfail(__FILE__, __LINE__, #x))
#else #else
extern void luaL_dbgbreak(void); #define lua_assert(x) ((void) (x))
#define lua_assert(x) ((x) ? (void) 0 : luaL_dbgbreak())
#endif
#endif #endif
#if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES) #if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES)
......
#include <stdio.h> #include <stdio.h>
int c_stdin = 999;
int c_stdout = 1000;
int c_stderr = 1001;
#if defined( LUA_NUMBER_INTEGRAL ) #if defined( LUA_NUMBER_INTEGRAL )
#include <stdarg.h> #include <stdarg.h>
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define lapi_c #define lapi_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
...@@ -25,7 +24,6 @@ ...@@ -25,7 +24,6 @@
#include "ltm.h" #include "ltm.h"
#include "lundump.h" #include "lundump.h"
#include "lvm.h" #include "lvm.h"
#include "lrotable.h"
#if 0 #if 0
const char lua_ident[] = const char lua_ident[] =
...@@ -242,6 +240,12 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { ...@@ -242,6 +240,12 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
LUA_API int lua_type (lua_State *L, int idx) { LUA_API int lua_type (lua_State *L, int idx) {
StkId o = index2adr(L, idx);
return (o == luaO_nilobject) ? LUA_TNONE : basettype(o);
}
LUA_API int lua_fulltype (lua_State *L, int idx) {
StkId o = index2adr(L, idx); StkId o = index2adr(L, idx);
return (o == luaO_nilobject) ? LUA_TNONE : ttype(o); return (o == luaO_nilobject) ? LUA_TNONE : ttype(o);
} }
...@@ -362,11 +366,10 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { ...@@ -362,11 +366,10 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API size_t lua_objlen (lua_State *L, int idx) { LUA_API size_t lua_objlen (lua_State *L, int idx) {
StkId o = index2adr(L, idx); StkId o = index2adr(L, idx);
switch (ttype(o)) { switch (basettype(o)) {
case LUA_TSTRING: return tsvalue(o)->len; case LUA_TSTRING: return tsvalue(o)->len;
case LUA_TUSERDATA: return uvalue(o)->len; case LUA_TUSERDATA: return uvalue(o)->len;
case LUA_TTABLE: return luaH_getn(hvalue(o)); case LUA_TTABLE: return luaH_getn(hvalue(o));
case LUA_TROTABLE: return luaH_getn_ro(rvalue(o));
case LUA_TNUMBER: { case LUA_TNUMBER: {
size_t l; size_t l;
lua_lock(L); /* `luaV_tostring' may create a new string */ lua_lock(L); /* `luaV_tostring' may create a new string */
...@@ -404,16 +407,14 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) { ...@@ -404,16 +407,14 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
LUA_API const void *lua_topointer (lua_State *L, int idx) { LUA_API const void *lua_topointer (lua_State *L, int idx) {
StkId o = index2adr(L, idx); StkId o = index2adr(L, idx);
switch (ttype(o)) { switch (ttype(o)) {
case LUA_TTABLE: return hvalue(o); case LUA_TTABLE:
case LUA_TROTABLE:
return hvalue(o);
case LUA_TFUNCTION: return clvalue(o); case LUA_TFUNCTION: return clvalue(o);
case LUA_TTHREAD: return thvalue(o); case LUA_TTHREAD: return thvalue(o);
case LUA_TUSERDATA: case LUA_TUSERDATA: return lua_touserdata(L, idx);
case LUA_TLIGHTUSERDATA: case LUA_TLIGHTUSERDATA: return pvalue(o);
return lua_touserdata(L, idx); case LUA_TLIGHTFUNCTION: return fvalue(o);
case LUA_TROTABLE:
return rvalue(o);
case LUA_TLIGHTFUNCTION:
return fvalue(o);
default: return NULL; default: return NULL;
} }
} }
...@@ -491,18 +492,23 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { ...@@ -491,18 +492,23 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
Closure *cl;
lua_lock(L); lua_lock(L);
luaC_checkGC(L); if (n == 0) {
api_checknelems(L, n); setfvalue(L->top, fn);
cl = luaF_newCclosure(L, n, getcurrenv(L)); api_incr_top(L);
cl->c.f = fn; } else {
L->top -= n; Closure *cl;
while (n--) luaC_checkGC(L);
setobj2n(L, &cl->c.upvalue[n], L->top+n); api_checknelems(L, n);
setclvalue(L, L->top, cl); cl = luaF_newCclosure(L, n, getcurrenv(L));
lua_assert(iswhite(obj2gco(cl))); cl->c.f = fn;
api_incr_top(L); L->top -= n;
while (n--)
setobj2n(L, &cl->c.upvalue[n], L->top+n);
setclvalue(L, L->top, cl);
lua_assert(iswhite(obj2gco(cl)));
api_incr_top(L);
}
lua_unlock(L); lua_unlock(L);
} }
...@@ -522,16 +528,10 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { ...@@ -522,16 +528,10 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
lua_unlock(L); lua_unlock(L);
} }
LUA_API void lua_pushrotable (lua_State *L, void *p) {
lua_lock(L);
setrvalue(L->top, p);
api_incr_top(L);
lua_unlock(L);
}
LUA_API void lua_pushlightfunction(lua_State *L, void *p) { LUA_API void lua_pushrotable (lua_State *L, const ROTable *t) {
lua_lock(L); lua_lock(L);
setfvalue(L->top, p); sethvalue(L, L->top, cast(ROTable *,t));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
...@@ -561,7 +561,6 @@ LUA_API void lua_gettable (lua_State *L, int idx) { ...@@ -561,7 +561,6 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
lua_unlock(L); lua_unlock(L);
} }
LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
StkId t; StkId t;
TValue key; TValue key;
...@@ -579,12 +578,10 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { ...@@ -579,12 +578,10 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
LUA_API void lua_rawget (lua_State *L, int idx) { LUA_API void lua_rawget (lua_State *L, int idx) {
StkId t; StkId t;
const TValue *res;
lua_lock(L); lua_lock(L);
t = index2adr(L, idx); t = index2adr(L, idx);
api_check(L, ttistable(t) || ttisrotable(t)); api_check(L, ttistable(t));
res = ttistable(t) ? luaH_get(hvalue(t), L->top - 1) : luaH_get_ro(rvalue(t), L->top - 1); setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
setobj2s(L, L->top - 1, res);
lua_unlock(L); lua_unlock(L);
} }
...@@ -593,8 +590,8 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { ...@@ -593,8 +590,8 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
StkId o; StkId o;
lua_lock(L); lua_lock(L);
o = index2adr(L, idx); o = index2adr(L, idx);
api_check(L, ttistable(o) || ttisrotable(o)); api_check(L, ttistable(o));
setobj2s(L, L->top, ttistable(o) ? luaH_getnum(hvalue(o), n) : luaH_getnum_ro(rvalue(o), n)) setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
...@@ -615,27 +612,21 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { ...@@ -615,27 +612,21 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
int res; int res;
lua_lock(L); lua_lock(L);
obj = index2adr(L, objindex); obj = index2adr(L, objindex);
switch (ttype(obj)) { switch (basettype(obj)) {
case LUA_TTABLE: case LUA_TTABLE:
mt = hvalue(obj)->metatable; mt = hvalue(obj)->metatable;
break; break;
case LUA_TUSERDATA: case LUA_TUSERDATA:
mt = uvalue(obj)->metatable; mt = uvalue(obj)->metatable;
break; break;
case LUA_TROTABLE:
mt = (Table*)luaR_getmeta(rvalue(obj));
break;
default: default:
mt = G(L)->mt[ttype(obj)]; mt = G(L)->mt[basettype(obj)];
break; break;
} }
if (mt == NULL) if (mt == NULL)
res = 0; res = 0;
else { else {
if(luaR_isrotable(mt)) sethvalue(L, L->top, mt)
setrvalue(L->top, mt)
else
sethvalue(L, L->top, mt)
api_incr_top(L); api_incr_top(L);
res = 1; res = 1;
} }
...@@ -732,37 +723,34 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) { ...@@ -732,37 +723,34 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
LUA_API int lua_setmetatable (lua_State *L, int objindex) { LUA_API int lua_setmetatable (lua_State *L, int objindex) {
TValue *obj; TValue *obj;
Table *mt; Table *mt;
int isrometa = 0;
lua_lock(L); lua_lock(L);
api_checknelems(L, 1); api_checknelems(L, 1);
obj = index2adr(L, objindex); obj = index2adr(L, objindex);
api_checkvalidindex(L, obj); api_checkvalidindex(L, obj);
if (ttisnil(L->top - 1)) if (ttisnil(L->top - 1)) {
mt = NULL; mt = NULL;
else { } else {
api_check(L, ttistable(L->top - 1) || ttisrotable(L->top - 1)); api_check(L, ttistable(L->top - 1));
if (ttistable(L->top - 1)) mt = hvalue(L->top - 1);
mt = hvalue(L->top - 1);
else {
mt = (Table*)rvalue(L->top - 1);
isrometa = 1;
}
} }
switch (ttype(obj)) { switch (ttype(obj)) { /* use basetype to retain subtypes*/
case LUA_TTABLE: { case LUA_TTABLE: {
hvalue(obj)->metatable = mt; hvalue(obj)->metatable = mt;
if (mt && !isrometa) if (mt && !isrotable(mt))
luaC_objbarriert(L, hvalue(obj), mt); luaC_objbarriert(L, hvalue(obj), mt);
break; break;
} }
case LUA_TUSERDATA: { case LUA_TUSERDATA: {
uvalue(obj)->metatable = mt; uvalue(obj)->metatable = mt;
if (mt && !isrometa) if (mt && !isrotable(mt))
luaC_objbarrier(L, rawuvalue(obj), mt); luaC_objbarrier(L, rawuvalue(obj), mt);
break; break;
} }
case LUA_TISROTABLE: { /* Ignore any changes to a ROTable MT */
break;
}
default: { default: {
G(L)->mt[ttype(obj)] = mt; G(L)->mt[basettype(obj)] = mt;
break; break;
} }
} }
...@@ -913,14 +901,14 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, ...@@ -913,14 +901,14 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
} }
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data) { LUA_API int lua_dumpEx (lua_State *L, lua_Writer writer, void *data, int stripping) {
int status; int status;
TValue *o; TValue *o;
lua_lock(L); lua_lock(L);
api_checknelems(L, 1); api_checknelems(L, 1);
o = L->top - 1; o = L->top - 1;
if (isLfunction(o)) if (isLfunction(o))
status = luaU_dump(L, clvalue(o)->l.p, writer, data, 0); status = luaU_dump(L, clvalue(o)->l.p, writer, data, stripping);
else else
status = 1; status = 1;
lua_unlock(L); lua_unlock(L);
...@@ -1038,8 +1026,8 @@ LUA_API int lua_next (lua_State *L, int idx) { ...@@ -1038,8 +1026,8 @@ LUA_API int lua_next (lua_State *L, int idx) {
int more; int more;
lua_lock(L); lua_lock(L);
t = index2adr(L, idx); t = index2adr(L, idx);
api_check(L, ttistable(t) || ttisrotable(t)); api_check(L, ttistable(t));
more = ttistable(t) ? luaH_next(L, hvalue(t), L->top - 1) : luaH_next_ro(L, rvalue(t), L->top - 1); more = luaH_next(L, hvalue(t), L->top - 1);
if (more) { if (more) {
api_incr_top(L); api_incr_top(L);
} }
...@@ -1148,3 +1136,15 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { ...@@ -1148,3 +1136,15 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
return name; return name;
} }
LUA_API void lua_setegcmode( lua_State *L, int mode, int limit) {
G(L)->egcmode = mode;
G(L)->memlimit = limit;
}
LUA_API void legc_set_mode(lua_State *L, int mode, int limit) {
global_State *g = G(L);
g->egcmode = mode;
g->memlimit = limit;
}
...@@ -4,27 +4,21 @@ ...@@ -4,27 +4,21 @@
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include <ctype.h> #include <ctype.h>
#ifdef __MINGW__ #if defined(LUA_CROSS_COMPILER) && defined(_MSC_VER)
#include <errno.h> #undef errno //msvc #defines errno, which interferes with our #include macro
#else #else
#ifdef _MSC_VER //msvc #defines errno, which interferes with our #include macro
#undef errno
#endif
#include <errno.h> #include <errno.h>
#endif #endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
#include "vfs.h" #include "vfs.h"
#include "user_interface.h" #include "user_interface.h"
#else
#endif #endif
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
/* This file uses only the official API of Lua. /* This file uses only the official API of Lua.
** Any function declared here could be written as an application function. ** Any function declared here could be written as an application function.
...@@ -38,14 +32,13 @@ ...@@ -38,14 +32,13 @@
#include "ldo.h" #include "ldo.h"
#include "lobject.h" #include "lobject.h"
#include "lstate.h" #include "lstate.h"
#include "legc.h"
#define FREELIST_REF 0 /* free list of references */ #define FREELIST_REF 0 /* free list of references */
/* convert a stack index to positive */ /* convert a stack index to positive */
#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \ #define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
lua_gettop(L) + (i) + 1) lua_gettop(L) + (i) + 1)
// Parameters for luaI_openlib // Parameters for luaI_openlib
#define LUA_USECCLOSURES 0 #define LUA_USECCLOSURES 0
...@@ -221,7 +214,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { ...@@ -221,7 +214,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s", const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg)); tname, lua_typename(L, narg));
return luaL_argerror(L, narg, msg); return luaL_argerror(L, narg, msg);
} }
...@@ -281,7 +274,7 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { ...@@ -281,7 +274,7 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
return 1; return 1;
} }
LUALIB_API int luaL_rometatable (lua_State *L, const char* tname, void *p) { LUALIB_API int luaL_rometatable (lua_State *L, const char* tname, const ROTable *p) {
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */
if (!lua_isnil(L, -1)) /* name already in use? */ if (!lua_isnil(L, -1)) /* name already in use? */
return 0; /* leave previous value on top, but return 0 */ return 0; /* leave previous value on top, but return 0 */
...@@ -319,22 +312,6 @@ LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { ...@@ -319,22 +312,6 @@ LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
tag_error(L, narg, t); tag_error(L, narg, t);
} }
LUALIB_API void luaL_checkanyfunction (lua_State *L, int narg) {
if (lua_type(L, narg) != LUA_TFUNCTION && lua_type(L, narg) != LUA_TLIGHTFUNCTION) {
const char *msg = lua_pushfstring(L, "function or lightfunction expected, got %s",
luaL_typename(L, narg));
luaL_argerror(L, narg, msg);
}
}
LUALIB_API void luaL_checkanytable (lua_State *L, int narg) {
if (lua_type(L, narg) != LUA_TTABLE && lua_type(L, narg) != LUA_TROTABLE) {
const char *msg = lua_pushfstring(L, "table or rotable expected, got %s",
luaL_typename(L, narg));
luaL_argerror(L, narg, msg);
}
}
LUALIB_API void luaL_checkany (lua_State *L, int narg) { LUALIB_API void luaL_checkany (lua_State *L, int narg) {
if (lua_type(L, narg) == LUA_TNONE) if (lua_type(L, narg) == LUA_TNONE)
...@@ -453,7 +430,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname, ...@@ -453,7 +430,7 @@ LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
for (i=0; i<nup; i++) /* copy upvalues to the top */ for (i=0; i<nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -nup); lua_pushvalue(L, -nup);
if (ftype == LUA_USELIGHTFUNCTIONS) if (ftype == LUA_USELIGHTFUNCTIONS)
lua_pushlightfunction(L, l->func); lua_pushcfunction(L, l->func);
else else
lua_pushcclosure(L, l->func, nup); lua_pushcclosure(L, l->func, nup);
lua_setfield(L, -(nup+2), l->name); lua_setfield(L, -(nup+2), l->name);
...@@ -565,7 +542,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx, ...@@ -565,7 +542,7 @@ LUALIB_API const char *luaL_findtable (lua_State *L, int idx,
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_settable(L, -4); /* set new table into field */ lua_settable(L, -4); /* set new table into field */
} }
else if (!lua_istable(L, -1) && !lua_isrotable(L, -1)) { /* field has a non-table value? */ else if (!lua_istable(L, -1)) { /* field has a non-table value? */
lua_pop(L, 2); /* remove table and value */ lua_pop(L, 2); /* remove table and value */
return fname; /* return problematic part of the name */ return fname; /* return problematic part of the name */
} }
...@@ -714,14 +691,32 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { ...@@ -714,14 +691,32 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
** ======================================================= ** =======================================================
*/ */
#ifdef LUA_CROSS_COMPILER
typedef struct LoadF { typedef struct LoadF {
int extraline; int extraline;
#ifdef LUA_CROSS_COMPILER
FILE *f; FILE *f;
#else
int f;
#endif
char buff[LUAL_BUFFERSIZE]; char buff[LUAL_BUFFERSIZE];
} LoadF; } LoadF;
#ifdef LUA_CROSS_COMPILER
# define freopen_bin(f,fn) freopen(f,"rb",fn)
# define read_buff(b,f) fread(b, 1, sizeof (b), f)
#else
# define strerror(n) ""
#undef feof
# define feof(f) vfs_eof(f)
#undef fopen
# define fopen(f, m) vfs_open(f, m)
# define freopen_bin(fn,f) ((void) vfs_close(f), vfs_open(fn, "r"))
#undef getc
# define getc(f) vfs_getc(f)
#undef ungetc
# define ungetc(c,f) vfs_ungetc(c, f)
# define read_buff(b,f) vfs_read(f, b, sizeof (b))
#endif
static const char *getF (lua_State *L, void *ud, size_t *size) { static const char *getF (lua_State *L, void *ud, size_t *size) {
LoadF *lf = (LoadF *)ud; LoadF *lf = (LoadF *)ud;
...@@ -732,7 +727,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { ...@@ -732,7 +727,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
return "\n"; return "\n";
} }
if (feof(lf->f)) return NULL; if (feof(lf->f)) return NULL;
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); *size = read_buff(lf->buff, lf->f);
return (*size > 0) ? lf->buff : NULL; return (*size > 0) ? lf->buff : NULL;
} }
...@@ -752,14 +747,19 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { ...@@ -752,14 +747,19 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
int c; int c;
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
lf.extraline = 0; lf.extraline = 0;
if (filename == NULL) { if (filename == NULL) {
#ifdef LUA_CROSS_COMPILER
lua_pushliteral(L, "=stdin"); lua_pushliteral(L, "=stdin");
lf.f = c_stdin; lf.f = stdin;
#else
return luaL_error(L, "filename is NULL");
#endif
} }
else { else {
lua_pushfstring(L, "@%s", filename); lua_pushfstring(L, "@%s", filename);
lf.f = fopen(filename, "r"); lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex); if (!lf.f) return errfile(L, "open", fnameindex);
} }
c = getc(lf.f); c = getc(lf.f);
if (c == '#') { /* Unix exec. file? */ if (c == '#') { /* Unix exec. file? */
...@@ -768,8 +768,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { ...@@ -768,8 +768,8 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
if (c == '\n') c = getc(lf.f); if (c == '\n') c = getc(lf.f);
} }
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ lf.f = freopen_bin(filename, lf.f); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex); if (!lf.f) return errfile(L, "reopen", fnameindex);
/* skip eventual `#!...' */ /* skip eventual `#!...' */
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {} while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {}
...@@ -777,91 +777,21 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { ...@@ -777,91 +777,21 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
} }
ungetc(c, lf.f); ungetc(c, lf.f);
status = lua_load(L, getF, &lf, lua_tostring(L, -1)); status = lua_load(L, getF, &lf, lua_tostring(L, -1));
#ifdef LUA_CROSS_COMPILER
readstatus = ferror(lf.f); readstatus = ferror(lf.f);
if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (filename) fclose(lf.f); /* close file (even in case of errors) */
if (readstatus) { if (readstatus) {
lua_settop(L, fnameindex); /* ignore results from `lua_load' */ lua_settop(L, fnameindex); /* ignore results from `lua_load' */
return errfile(L, "read", fnameindex); return errfile(L, "read", fnameindex);
} }
lua_remove(L, fnameindex);
return status;
}
#else #else
(void) readstatus; /* avoid compile error */
typedef struct LoadFSF {
int extraline;
int f;
char buff[LUAL_BUFFERSIZE];
} LoadFSF;
static const char *getFSF (lua_State *L, void *ud, size_t *size) {
LoadFSF *lf = (LoadFSF *)ud;
(void)L;
if (L == NULL && size == NULL) // Direct mode check
return NULL;
if (lf->extraline) {
lf->extraline = 0;
*size = 1;
return "\n";
}
if (vfs_eof(lf->f)) return NULL;
*size = vfs_read(lf->f, lf->buff, sizeof(lf->buff));
return (*size > 0) ? lf->buff : NULL;
}
static int errfsfile (lua_State *L, const char *what, int fnameindex) {
const char *filename = lua_tostring(L, fnameindex) + 1;
lua_pushfstring(L, "cannot %s %s", what, filename);
lua_remove(L, fnameindex);
return LUA_ERRFILE;
}
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
LoadFSF lf;
int status, c;
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
lf.extraline = 0;
if (filename == NULL) {
return luaL_error(L, "filename is NULL");
}
else {
lua_pushfstring(L, "@%s", filename);
lf.f = vfs_open(filename, "r");
if (!lf.f) return errfsfile(L, "open", fnameindex);
}
// if(fs_size(lf.f)>LUAL_BUFFERSIZE)
// return luaL_error(L, "file is too big");
c = vfs_getc(lf.f);
if (c == '#') { /* Unix exec. file? */
lf.extraline = 1;
while ((c = vfs_getc(lf.f)) != VFS_EOF && c != '\n') ; /* skip first line */
if (c == '\n') c = vfs_getc(lf.f);
}
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
vfs_close(lf.f);
lf.f = vfs_open(filename, "r"); /* reopen in binary mode */
if (!lf.f) return errfsfile(L, "reopen", fnameindex);
/* skip eventual `#!...' */
while ((c = vfs_getc(lf.f)) != VFS_EOF && c != LUA_SIGNATURE[0]) ;
lf.extraline = 0;
}
vfs_ungetc(c, lf.f);
status = lua_load(L, getFSF, &lf, lua_tostring(L, -1));
if (filename) vfs_close(lf.f); /* close file (even in case of errors) */ if (filename) vfs_close(lf.f); /* close file (even in case of errors) */
#endif
lua_remove(L, fnameindex); lua_remove(L, fnameindex);
return status; return status;
} }
#endif
typedef struct LoadS { typedef struct LoadS {
const char *s; const char *s;
...@@ -959,7 +889,7 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) ...@@ -959,7 +889,7 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
#endif #endif
} }
#if defined(DEVELOPMENT_USE_GDB) && !defined(LUA_CROSS_COMPILER) #ifdef DEVELOPMENT_USE_GDB
/* /*
* This is a simple stub used by lua_assert() if DEVELOPMENT_USE_GDB is defined. * This is a simple stub used by lua_assert() if DEVELOPMENT_USE_GDB is defined.
* Instead of crashing out with an assert error, this hook starts the GDB remote * Instead of crashing out with an assert error, this hook starts the GDB remote
...@@ -969,9 +899,14 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) ...@@ -969,9 +899,14 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
* is the option to exit the interactive session and start the Xtensa remote GDB * is the option to exit the interactive session and start the Xtensa remote GDB
* which will then sync up with the remote GDB client to allow forensics of the error. * which will then sync up with the remote GDB client to allow forensics of the error.
*/ */
#ifdef LUA_CROSS_COMPILER
LUALIB_API void lua_debugbreak(void) {
puts(" lua_debugbreak "); /* allows BT analysis of assert fails */
}
#else
extern void gdbstub_init(void); extern void gdbstub_init(void);
LUALIB_API void luaL_dbgbreak(void) { LUALIB_API void lua_debugbreak(void) {
static int repeat_entry = 0; static int repeat_entry = 0;
if (repeat_entry == 0) { if (repeat_entry == 0) {
dbg_printf("Start up the gdb stub if not already started\n"); dbg_printf("Start up the gdb stub if not already started\n");
...@@ -981,17 +916,13 @@ LUALIB_API void luaL_dbgbreak(void) { ...@@ -981,17 +916,13 @@ LUALIB_API void luaL_dbgbreak(void) {
asm("break 0,0" ::); asm("break 0,0" ::);
} }
#endif #endif
#endif
static int panic (lua_State *L) { static int panic (lua_State *L) {
(void)L; /* to avoid warnings */ (void)L; /* to avoid warnings */
#if defined(LUA_USE_STDIO) lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
fprintf(c_stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1)); lua_tostring(L, -1));
#else
luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
lua_tostring(L, -1));
#endif
while (1) {} while (1) {}
return 0; return 0;
} }
......
...@@ -60,11 +60,9 @@ LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, ...@@ -60,11 +60,9 @@ LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg); LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API void (luaL_checkanyfunction) (lua_State *L, int narg);
LUALIB_API void (luaL_checkanytable) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API int (luaL_rometatable) (lua_State *L, const char* tname, void *p); LUALIB_API int (luaL_rometatable) (lua_State *L, const char* tname, const ROTable *p);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl); LUALIB_API void (luaL_where) (lua_State *L, int lvl);
...@@ -76,11 +74,8 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, ...@@ -76,11 +74,8 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
LUALIB_API int (luaL_ref) (lua_State *L, int t); LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
#ifdef LUA_CROSS_COMPILER
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
#else
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
#endif
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
const char *name); const char *name);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
...@@ -111,6 +106,8 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message) ...@@ -111,6 +106,8 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE);
#define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION);
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
...@@ -163,6 +160,11 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); ...@@ -163,6 +160,11 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
/* }====================================================== */ /* }====================================================== */
LUALIB_API int luaL_traceback (lua_State *L);
LUALIB_API int luaL_pcallx (lua_State *L, int narg, int nres);
LUALIB_API int luaL_posttask( lua_State* L, int prio );
/* }====================================================== */
/* compatibility with ref system */ /* compatibility with ref system */
......
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
#define lbaselib_c #define lbaselib_c
#define LUA_LIB #define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include "lnodemcu.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "lrotable.h"
/* /*
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
** model but changing `fputs' to put the strings at a proper place ** model but changing `fputs' to put the strings at a proper place
** (a console window or a log file, for instance). ** (a console window or a log file, for instance).
*/ */
#ifdef LUA_CROSS_COMPILER
#undef puts
#define puts(s) printf("%s",s)
#endif
static int luaB_print (lua_State *L) { static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
int i; int i;
...@@ -101,7 +105,7 @@ static int luaB_getmetatable (lua_State *L) { ...@@ -101,7 +105,7 @@ static int luaB_getmetatable (lua_State *L) {
static int luaB_setmetatable (lua_State *L) { static int luaB_setmetatable (lua_State *L) {
int t = lua_type(L, 2); int t = lua_type(L, 2);
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE || t == LUA_TROTABLE, 2, luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
"nil or table expected"); "nil or table expected");
if (luaL_getmetafield(L, 1, "__metatable")) if (luaL_getmetafield(L, 1, "__metatable"))
luaL_error(L, "cannot change a protected metatable"); luaL_error(L, "cannot change a protected metatable");
...@@ -164,7 +168,7 @@ static int luaB_rawequal (lua_State *L) { ...@@ -164,7 +168,7 @@ static int luaB_rawequal (lua_State *L) {
static int luaB_rawget (lua_State *L) { static int luaB_rawget (lua_State *L) {
luaL_checkanytable(L, 1); luaL_checktable(L, 1);
luaL_checkany(L, 2); luaL_checkany(L, 2);
lua_settop(L, 2); lua_settop(L, 2);
lua_rawget(L, 1); lua_rawget(L, 1);
...@@ -172,7 +176,7 @@ static int luaB_rawget (lua_State *L) { ...@@ -172,7 +176,7 @@ static int luaB_rawget (lua_State *L) {
} }
static int luaB_rawset (lua_State *L) { static int luaB_rawset (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktable(L, 1);
luaL_checkany(L, 2); luaL_checkany(L, 2);
luaL_checkany(L, 3); luaL_checkany(L, 3);
lua_settop(L, 3); lua_settop(L, 3);
...@@ -222,7 +226,7 @@ static int luaB_type (lua_State *L) { ...@@ -222,7 +226,7 @@ static int luaB_type (lua_State *L) {
static int luaB_next (lua_State *L) { static int luaB_next (lua_State *L) {
luaL_checkanytable(L, 1); luaL_checktable(L, 1);
lua_settop(L, 2); /* create a 2nd argument if there isn't one */ lua_settop(L, 2); /* create a 2nd argument if there isn't one */
if (lua_next(L, 1)) if (lua_next(L, 1))
return 2; return 2;
...@@ -234,7 +238,7 @@ static int luaB_next (lua_State *L) { ...@@ -234,7 +238,7 @@ static int luaB_next (lua_State *L) {
static int luaB_pairs (lua_State *L) { static int luaB_pairs (lua_State *L) {
luaL_checkanytable(L, 1); luaL_checktable(L, 1);
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
lua_pushvalue(L, 1); /* state, */ lua_pushvalue(L, 1); /* state, */
lua_pushnil(L); /* and initial value */ lua_pushnil(L); /* and initial value */
...@@ -244,7 +248,7 @@ static int luaB_pairs (lua_State *L) { ...@@ -244,7 +248,7 @@ static int luaB_pairs (lua_State *L) {
static int ipairsaux (lua_State *L) { static int ipairsaux (lua_State *L) {
int i = luaL_checkint(L, 2); int i = luaL_checkint(L, 2);
luaL_checkanytable(L, 1); luaL_checktable(L, 1);
i++; /* next value */ i++; /* next value */
lua_pushinteger(L, i); lua_pushinteger(L, i);
lua_rawgeti(L, 1, i); lua_rawgeti(L, 1, i);
...@@ -253,7 +257,7 @@ static int ipairsaux (lua_State *L) { ...@@ -253,7 +257,7 @@ static int ipairsaux (lua_State *L) {
static int luaB_ipairs (lua_State *L) { static int luaB_ipairs (lua_State *L) {
luaL_checkanytable(L, 1); luaL_checktable(L, 1);
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
lua_pushvalue(L, 1); /* state, */ lua_pushvalue(L, 1); /* state, */
lua_pushinteger(L, 0); /* and initial value */ lua_pushinteger(L, 0); /* and initial value */
...@@ -451,29 +455,24 @@ static int luaB_newproxy (lua_State *L) { ...@@ -451,29 +455,24 @@ static int luaB_newproxy (lua_State *L) {
return 1; return 1;
} }
#include "lrotable.h"
LROT_EXTERN(lua_rotable_base);
/* /*
* Separate ROTables are used for the base functions and library ROTables, with ** ESP builds use specific linker directives to marshal all the ROTable entries
* the base functions ROTable declared below. The library ROTable is chained ** for the library modules including the base library into an entry vector in
* from this using its __index meta-method. ** the PSECT ".lua_rotable" including the base library entries; this is bound
* ** into a ROTable in linit.c which then hooked into the __index metaentry for
* ESP builds use specific linker directives to marshal all the ROTable entries ** _G so that base library and ROM tables are directly resolved through _G.
* for the library modules into a single ROTable in the PSECT ".lua_rotable". **
* This is not practical on Posix builds using a standard GNU link, so the ** The host-based luac.cross builds which must use a standard GNU link or
* equivalent ROTable for the core libraries defined in linit.c for the cross- ** MSVC so this linker-specfic assembly approach can't be used. In this case
* compiler build. ** luaopen_base returns a base_func ROTable so a two cascade resolution. See
*/ ** description in init.c for further details.
*/
LROT_EXTERN(lua_rotables); #ifdef LUA_CROSS_COMPILER
LROT_BEGIN(base_func, NULL, 0)
LROT_PUBLIC_BEGIN(base_func_meta) #else
LROT_TABENTRY( __index, lua_rotables ) LROT_ENTRIES_IN_SECTION(base_func, rotable)
LROT_END(base_func, base_func_meta, LROT_MASK_INDEX) #endif
LROT_PUBLIC_BEGIN(base_func)
LROT_FUNCENTRY(assert, luaB_assert) LROT_FUNCENTRY(assert, luaB_assert)
LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage) LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage)
LROT_FUNCENTRY(dofile, luaB_dofile) LROT_FUNCENTRY(dofile, luaB_dofile)
...@@ -498,13 +497,11 @@ LROT_PUBLIC_BEGIN(base_func) ...@@ -498,13 +497,11 @@ LROT_PUBLIC_BEGIN(base_func)
LROT_FUNCENTRY(type, luaB_type) LROT_FUNCENTRY(type, luaB_type)
LROT_FUNCENTRY(unpack, luaB_unpack) LROT_FUNCENTRY(unpack, luaB_unpack)
LROT_FUNCENTRY(xpcall, luaB_xpcall) LROT_FUNCENTRY(xpcall, luaB_xpcall)
LROT_TABENTRY(__metatable, base_func_meta) #ifdef LUA_CROSS_COMPILER
LROT_END(base_func, base_func_meta, LROT_MASK_INDEX) LROT_END(base_func, NULL, 0)
#else
LROT_BEGIN(G_meta) LROT_BREAK(base_func)
LROT_TABENTRY( __index, base_func ) #endif
LROT_END(G_meta, NULL, 0)
/* /*
** {====================================================== ** {======================================================
...@@ -634,14 +631,14 @@ static int luaB_corunning (lua_State *L) { ...@@ -634,14 +631,14 @@ static int luaB_corunning (lua_State *L) {
return 1; return 1;
} }
LROT_PUBLIC_BEGIN(co_funcs) LROT_BEGIN(co_funcs, NULL, 0)
LROT_FUNCENTRY( create, luaB_cocreate ) LROT_FUNCENTRY( create, luaB_cocreate )
LROT_FUNCENTRY( resume, luaB_coresume ) LROT_FUNCENTRY( resume, luaB_coresume )
LROT_FUNCENTRY( running, luaB_corunning ) LROT_FUNCENTRY( running, luaB_corunning )
LROT_FUNCENTRY( status, luaB_costatus ) LROT_FUNCENTRY( status, luaB_costatus )
LROT_FUNCENTRY( wrap, luaB_cowrap ) LROT_FUNCENTRY( wrap, luaB_cowrap )
LROT_FUNCENTRY( yield, luaB_yield ) LROT_FUNCENTRY( yield, luaB_yield )
LROT_END (co_funcs, NULL, 0) LROT_END(co_funcs, NULL, 0)
/* }====================================================== */ /* }====================================================== */
...@@ -650,19 +647,13 @@ static void auxopen (lua_State *L, const char *name, ...@@ -650,19 +647,13 @@ static void auxopen (lua_State *L, const char *name,
lua_CFunction f, lua_CFunction u) { lua_CFunction f, lua_CFunction u) {
lua_pushcfunction(L, u); lua_pushcfunction(L, u);
lua_pushcclosure(L, f, 1); lua_pushcclosure(L, f, 1);
lua_setfield(L, -2, name); lua_setglobal(L, name);
} }
static void base_open (lua_State *L) { extern LROT_TABLE(rotables);
/* set global _G */ LUALIB_API int luaopen_base (lua_State *L) {
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "_G"); lua_settable(L, LUA_GLOBALSINDEX); /* set global _G */
/* open lib into global table */
luaL_register_light(L, "_G", &((luaL_Reg) {0}));
lua_pushrotable(L, LROT_TABLEREF(G_meta));
lua_setmetatable(L, LUA_GLOBALSINDEX);
lua_pushliteral(L, LUA_VERSION); lua_pushliteral(L, LUA_VERSION);
lua_setglobal(L, "_VERSION"); /* set global _VERSION */ lua_setglobal(L, "_VERSION"); /* set global _VERSION */
/* `ipairs' and `pairs' need auxliliary functions as upvalues */ /* `ipairs' and `pairs' need auxliliary functions as upvalues */
...@@ -670,16 +661,15 @@ static void base_open (lua_State *L) { ...@@ -670,16 +661,15 @@ static void base_open (lua_State *L) {
auxopen(L, "pairs", luaB_pairs, luaB_next); auxopen(L, "pairs", luaB_pairs, luaB_next);
/* `newproxy' needs a weaktable as upvalue */ /* `newproxy' needs a weaktable as upvalue */
lua_createtable(L, 0, 1); /* new table `w' */ lua_createtable(L, 0, 1); /* new table `w' */
lua_pushvalue(L, -1); /* `w' will be its own metatable */
lua_setmetatable(L, -2);
lua_pushliteral(L, "kv"); lua_pushliteral(L, "kv");
lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
lua_pushcclosure(L, luaB_newproxy, 1); lua_pushvalue(L, -1); /* `w' will be its own metatable */
lua_setmetatable(L, -2);
lua_pushcclosure(L, luaB_newproxy, 1); /* Upval is table w */
lua_setglobal(L, "newproxy"); /* set global `newproxy' */ lua_setglobal(L, "newproxy"); /* set global `newproxy' */
} lua_pushrotable(L, LROT_TABLEREF(rotables));
lua_setglobal(L, "__index");
lua_pushvalue(L, LUA_GLOBALSINDEX); /* _G is its own metatable */
LUALIB_API int luaopen_base (lua_State *L) { lua_setmetatable(L, LUA_GLOBALSINDEX);
base_open(L); return 0;
return 1;
} }
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#define lcode_c #define lcode_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include <stdlib.h> #include <stdlib.h>
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#define ldblib_c #define ldblib_c
#define LUA_LIB #define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include <stdio.h> #include <stdio.h>
...@@ -18,7 +17,7 @@ ...@@ -18,7 +17,7 @@
#include "lualib.h" #include "lualib.h"
#include "lstring.h" #include "lstring.h"
#include "lflash.h" #include "lflash.h"
#include "lrotable.h" #include "lnodemcu.h"
#include "user_modules.h" #include "user_modules.h"
...@@ -144,7 +143,7 @@ static int db_getinfo (lua_State *L) { ...@@ -144,7 +143,7 @@ static int db_getinfo (lua_State *L) {
return 1; return 1;
} }
} }
else if (lua_isfunction(L, arg+1) || lua_islightfunction(L, arg+1)) { else if (lua_isfunction(L, arg+1)) {
lua_pushfstring(L, ">%s", options); lua_pushfstring(L, ">%s", options);
options = lua_tostring(L, -1); options = lua_tostring(L, -1);
lua_pushvalue(L, arg+1); lua_pushvalue(L, arg+1);
...@@ -302,7 +301,7 @@ static int db_sethook (lua_State *L) { ...@@ -302,7 +301,7 @@ static int db_sethook (lua_State *L) {
} }
else { else {
const char *smask = luaL_checkstring(L, arg+2); const char *smask = luaL_checkstring(L, arg+2);
luaL_checkanyfunction(L, arg+1); luaL_checkfunction(L, arg+1);
count = luaL_optint(L, arg+3, 0); count = luaL_optint(L, arg+3, 0);
func = hookf; mask = makemask(smask, count); func = hookf; mask = makemask(smask, count);
} }
...@@ -340,10 +339,10 @@ static int db_debug (lua_State *L) { ...@@ -340,10 +339,10 @@ static int db_debug (lua_State *L) {
for (;;) { for (;;) {
char buffer[LUA_MAXINPUT]; char buffer[LUA_MAXINPUT];
#if defined(LUA_USE_STDIO) #if defined(LUA_USE_STDIO)
fputs("lua_debug> ", c_stderr); fputs("lua_debug> ", stderr);
if (fgets(buffer, sizeof(buffer), c_stdin) == 0 || if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
#else #else
// luai_writestringerror("%s", "lua_debug>"); // lua_writestringerror("%s", "lua_debug>");
if (lua_readline(L, buffer, "lua_debug>") == 0 || if (lua_readline(L, buffer, "lua_debug>") == 0 ||
#endif #endif
strcmp(buffer, "cont\n") == 0) strcmp(buffer, "cont\n") == 0)
...@@ -351,10 +350,10 @@ static int db_debug (lua_State *L) { ...@@ -351,10 +350,10 @@ static int db_debug (lua_State *L) {
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
lua_pcall(L, 0, 0, 0)) { lua_pcall(L, 0, 0, 0)) {
#if defined(LUA_USE_STDIO) #if defined(LUA_USE_STDIO)
fputs(lua_tostring(L, -1), c_stderr); fputs(lua_tostring(L, -1), stderr);
fputs("\n", c_stderr); fputs("\n", stderr);
#else #else
luai_writestringerror("%s\n", lua_tostring(L, -1)); lua_writestringerror("%s\n", lua_tostring(L, -1));
#endif #endif
} }
lua_settop(L, 0); /* remove eventual returns */ lua_settop(L, 0); /* remove eventual returns */
...@@ -365,7 +364,7 @@ static int db_debug (lua_State *L) { ...@@ -365,7 +364,7 @@ static int db_debug (lua_State *L) {
#define LEVELS1 12 /* size of the first part of the stack */ #define LEVELS1 12 /* size of the first part of the stack */
#define LEVELS2 10 /* size of the second part of the stack */ #define LEVELS2 10 /* size of the second part of the stack */
int debug_errorfb (lua_State *L) { static int debug_errorfb (lua_State *L) {
int level; int level;
int firstpart = 1; /* still before eventual `...' */ int firstpart = 1; /* still before eventual `...' */
int arg; int arg;
...@@ -417,7 +416,7 @@ int debug_errorfb (lua_State *L) { ...@@ -417,7 +416,7 @@ int debug_errorfb (lua_State *L) {
return 1; return 1;
} }
LROT_PUBLIC_BEGIN(dblib) LROT_BEGIN(dblib, NULL, 0)
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL #ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
LROT_FUNCENTRY( debug, db_debug ) LROT_FUNCENTRY( debug, db_debug )
LROT_FUNCENTRY( getfenv, db_getfenv ) LROT_FUNCENTRY( getfenv, db_getfenv )
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#define ldebug_c #define ldebug_c
#define LUA_CORE #define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include <string.h> #include <string.h>
...@@ -327,21 +326,21 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { ...@@ -327,21 +326,21 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
lua_lock(L); lua_lock(L);
if (*what == '>') { if (*what == '>') {
StkId func = L->top - 1; StkId func = L->top - 1;
luai_apicheck(L, ttisfunction(func) || ttislightfunction(func)); luai_apicheck(L, ttisfunction(func));
what++; /* skip the '>' */ what++; /* skip the '>' */
if (ttisfunction(func)) if (ttislightfunction(func))
f = clvalue(func);
else
plight = fvalue(func); plight = fvalue(func);
else
f = clvalue(func);
L->top--; /* pop function */ L->top--; /* pop function */
} }
else if (ar->i_ci != 0) { /* no tail call? */ else if (ar->i_ci != 0) { /* no tail call? */
ci = L->base_ci + ar->i_ci; ci = L->base_ci + ar->i_ci;
lua_assert(ttisfunction(ci->func) || ttislightfunction(ci->func)); lua_assert(ttisfunction(ci->func));
if (ttisfunction(ci->func)) if (ttislightfunction(ci->func))
f = clvalue(ci->func);
else
plight = fvalue(ci->func); plight = fvalue(ci->func);
else
f = clvalue(ci->func);
} }
status = auxgetinfo(L, what, ar, f, plight, ci); status = auxgetinfo(L, what, ar, f, plight, ci);
if (strchr(what, 'f')) { if (strchr(what, 'f')) {
...@@ -721,7 +720,7 @@ static void addinfo (lua_State *L, const char *msg) { ...@@ -721,7 +720,7 @@ static void addinfo (lua_State *L, const char *msg) {
void luaG_errormsg (lua_State *L) { void luaG_errormsg (lua_State *L) {
if (L->errfunc != 0) { /* is there an error handling function? */ if (L->errfunc != 0) { /* is there an error handling function? */
StkId errfunc = restorestack(L, L->errfunc); StkId errfunc = restorestack(L, L->errfunc);
if (!ttisfunction(errfunc) && !ttislightfunction(errfunc)) luaD_throw(L, LUA_ERRERR); if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
setobjs2s(L, L->top, L->top - 1); /* move argument */ setobjs2s(L, L->top, L->top - 1); /* move argument */
setobjs2s(L, L->top - 1, errfunc); /* push function */ setobjs2s(L, L->top - 1, errfunc); /* push function */
incr_top(L); incr_top(L);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment