diff options
| -rw-r--r-- | inout.c | 51 | ||||
| -rw-r--r-- | inout.h | 5 | ||||
| -rw-r--r-- | table.c | 22 |
3 files changed, 47 insertions, 31 deletions
| @@ -5,7 +5,7 @@ | |||
| 5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | char *rcs_inout="$Id: inout.c,v 2.24 1995/10/23 13:54:11 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| @@ -132,27 +132,40 @@ void lua_internaldofile (void) | |||
| 132 | lua_pushnil(); | 132 | lua_pushnil(); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | /* | 135 | |
| 136 | ** Internal function: print object values | 136 | static char *tostring (lua_Object obj) |
| 137 | */ | ||
| 138 | void lua_print (void) | ||
| 139 | { | 137 | { |
| 140 | int i=1; | 138 | static char buff[20]; |
| 141 | lua_Object obj; | 139 | if (lua_isstring(obj)) |
| 142 | while ((obj=lua_getparam (i++)) != LUA_NOOBJECT) | 140 | return lua_getstring(obj); |
| 143 | { | 141 | if (lua_isnumber(obj)) |
| 144 | if (lua_isnumber(obj)) printf("%g\n",lua_getnumber(obj)); | 142 | sprintf(buff, "%g", lua_getnumber(obj)); |
| 145 | else if (lua_isstring(obj)) printf("%s\n",lua_getstring(obj)); | 143 | else if (lua_isfunction(obj)) |
| 146 | else if (lua_isfunction(obj)) printf("function: %p\n",(luaI_Address(obj))->value.tf); | 144 | sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf); |
| 147 | else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction(obj) | 145 | else if (lua_iscfunction(obj)) |
| 148 | ); | 146 | sprintf(buff, "cfunction: %p", lua_getcfunction(obj)); |
| 149 | else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata(obj)); | 147 | else if (lua_isuserdata(obj)) |
| 150 | else if (lua_istable(obj)) printf("table: %p\n",avalue(luaI_Address(obj))); | 148 | sprintf(buff, "userdata: %p", lua_getuserdata(obj)); |
| 151 | else if (lua_isnil(obj)) printf("nil\n"); | 149 | else if (lua_istable(obj)) |
| 152 | else printf("invalid value to print\n"); | 150 | sprintf(buff, "table: %p", avalue(luaI_Address(obj))); |
| 153 | } | 151 | else if (lua_isnil(obj)) |
| 152 | sprintf(buff, "nil"); | ||
| 153 | else buff[0] = 0; | ||
| 154 | return buff; | ||
| 154 | } | 155 | } |
| 155 | 156 | ||
| 157 | void luaI_tostring (void) | ||
| 158 | { | ||
| 159 | lua_pushstring(tostring(lua_getparam(1))); | ||
| 160 | } | ||
| 161 | |||
| 162 | void luaI_print (void) | ||
| 163 | { | ||
| 164 | int i = 1; | ||
| 165 | lua_Object obj; | ||
| 166 | while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) | ||
| 167 | printf("%s\n", tostring(obj)); | ||
| 168 | } | ||
| 156 | 169 | ||
| 157 | /* | 170 | /* |
| 158 | ** Internal function: return an object type. | 171 | ** Internal function: return an object type. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: inout.h,v 1.9 1995/05/16 17:23:58 roberto Exp roberto $ | 2 | ** $Id: inout.h,v 1.10 1995/10/17 11:58:41 roberto Exp roberto $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | 5 | ||
| @@ -21,7 +21,8 @@ void lua_closestring (void); | |||
| 21 | 21 | ||
| 22 | void lua_internaldofile (void); | 22 | void lua_internaldofile (void); |
| 23 | void lua_internaldostring (void); | 23 | void lua_internaldostring (void); |
| 24 | void lua_print (void); | 24 | void luaI_tostring (void); |
| 25 | void luaI_print (void); | ||
| 25 | void luaI_type (void); | 26 | void luaI_type (void); |
| 26 | void lua_obj2number (void); | 27 | void lua_obj2number (void); |
| 27 | void luaI_error (void); | 28 | void luaI_error (void); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.39 1996/01/09 20:23:19 roberto Exp $"; | 6 | char *rcs_table="$Id: table.c,v 2.40 1996/01/22 14:15:13 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | /*#include <string.h>*/ | 8 | /*#include <string.h>*/ |
| 9 | 9 | ||
| @@ -44,6 +44,14 @@ static void lua_initsymbol (void) | |||
| 44 | Word n; | 44 | Word n; |
| 45 | lua_maxsymbol = BUFFER_BLOCK; | 45 | lua_maxsymbol = BUFFER_BLOCK; |
| 46 | lua_table = newvector(lua_maxsymbol, Symbol); | 46 | lua_table = newvector(lua_maxsymbol, Symbol); |
| 47 | n = luaI_findsymbolbyname("nextvar"); | ||
| 48 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; | ||
| 49 | n = luaI_findsymbolbyname("error"); | ||
| 50 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; | ||
| 51 | n = luaI_findsymbolbyname("tonumber"); | ||
| 52 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; | ||
| 53 | n = luaI_findsymbolbyname("setfallback"); | ||
| 54 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; | ||
| 47 | n = luaI_findsymbolbyname("next"); | 55 | n = luaI_findsymbolbyname("next"); |
| 48 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; | 56 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; |
| 49 | n = luaI_findsymbolbyname("dofile"); | 57 | n = luaI_findsymbolbyname("dofile"); |
| @@ -52,20 +60,14 @@ static void lua_initsymbol (void) | |||
| 52 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = setglobal; | 60 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = setglobal; |
| 53 | n = luaI_findsymbolbyname("getglobal"); | 61 | n = luaI_findsymbolbyname("getglobal"); |
| 54 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = getglobal; | 62 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = getglobal; |
| 55 | n = luaI_findsymbolbyname("nextvar"); | ||
| 56 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; | ||
| 57 | n = luaI_findsymbolbyname("type"); | 63 | n = luaI_findsymbolbyname("type"); |
| 58 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type; | 64 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type; |
| 59 | n = luaI_findsymbolbyname("tonumber"); | 65 | n = luaI_findsymbolbyname("tostring"); |
| 60 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; | 66 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_tostring; |
| 61 | n = luaI_findsymbolbyname("print"); | 67 | n = luaI_findsymbolbyname("print"); |
| 62 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; | 68 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_print; |
| 63 | n = luaI_findsymbolbyname("dostring"); | 69 | n = luaI_findsymbolbyname("dostring"); |
| 64 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | 70 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; |
| 65 | n = luaI_findsymbolbyname("setfallback"); | ||
| 66 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback; | ||
| 67 | n = luaI_findsymbolbyname("error"); | ||
| 68 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; | ||
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | 73 | ||
