소스 검색

new function "getintmethod"

Roberto Ierusalimschy 28 년 전
부모
커밋
075b7918c3
6개의 변경된 파일30개의 추가작업 그리고 10개의 파일을 삭제
  1. 11 2
      fallback.c
  2. 2 1
      fallback.h
  3. 2 1
      inout.c
  4. 5 4
      iolib.c
  5. 2 1
      lua.h
  6. 8 1
      opcode.c

+ 11 - 2
fallback.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
  
-char *rcs_fallback="$Id: fallback.c,v 1.36 1997/03/31 20:59:09 roberto Exp roberto $";
+char *rcs_fallback="$Id: fallback.c,v 1.37 1997/04/02 22:52:42 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -223,6 +223,16 @@ TObject *luaI_getim (int tag, IMS event)
 }
 
 
+void luaI_getintmethod (void)
+{
+  int t = (int)luaL_check_number(1, "getintmethod");
+  int e = luaI_checkevent(luaL_check_string(2, "getintmethod"), luaI_eventname);
+  checktag(t);
+  if (validevent(t, e))
+    luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
+}
+
+
 void luaI_setintmethod (void)
 {
   int t = (int)luaL_check_number(1, "setintmethod");
@@ -233,7 +243,6 @@ void luaI_setintmethod (void)
     lua_error("cannot change this internal method");
   luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod",
                  3, "function expected");
-  luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
   luaI_IMtable[-t].int_method[e] = *luaI_Address(func);
 }
 

+ 2 - 1
fallback.h

@@ -1,5 +1,5 @@
 /*
-** $Id: fallback.h,v 1.19 1997/03/31 20:59:09 roberto Exp roberto $
+** $Id: fallback.h,v 1.20 1997/04/02 22:52:42 roberto Exp roberto $
 */
  
 #ifndef fallback_h
@@ -52,6 +52,7 @@ TObject *luaI_getim (int tag, IMS event);
 TObject *luaI_geterrorim (void);
 int luaI_tag (TObject *o);
 void luaI_setintmethod (void);
+void luaI_getintmethod (void);
 void luaI_seterrormethod (void);
 void luaI_initfallbacks (void);
 

+ 2 - 1
inout.c

@@ -5,7 +5,7 @@
 ** Also provides some predefined lua functions.
 */
 
-char *rcs_inout="$Id: inout.c,v 2.52 1997/04/01 19:02:43 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.53 1997/04/02 22:53:35 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -342,6 +342,7 @@ static struct {
   {"setfallback", luaI_setfallback},
   {"setglobal", luaI_setglobal},
   {"setintmethod", luaI_setintmethod},
+  {"getintmethod", luaI_getintmethod},
   {"settag", luaIl_settag},
   {"tonumber", lua_obj2number},
   {"tostring", luaI_tostring},

+ 5 - 4
iolib.c

@@ -288,9 +288,10 @@ static void getbyte (void)
     lua_pushnumber(lua_getbindatasize(ud));
   else {
     i--;
-    luaL_arg_check(0 <= i && i < lua_getbindatasize(ud), "getbyte", 2,
-                   "out of range");
-    lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
+    if (0 <= i && i < lua_getbindatasize(ud))
+      lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
+    else
+      lua_pushnil();
   }
 }
 
@@ -341,7 +342,7 @@ static struct luaL_reg iolib[] = {
 
 void iolib_open (void)
 {
-  lua_tagio = lua_newtag("userdata");
+  lua_tagio = lua_newtag();
   lua_infile=stdin; lua_outfile=stdout;
   luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
   lua_seterrormethod(errorfb);

+ 2 - 1
lua.h

@@ -2,7 +2,7 @@
 ** LUA - Linguagem para Usuarios de Aplicacao
 ** Grupo de Tecnologia em Computacao Grafica
 ** TeCGraf - PUC-Rio
-** $Id: lua.h,v 3.40 1997/04/02 17:44:18 roberto Exp roberto $
+** $Id: lua.h,v 3.41 1997/04/02 22:52:42 roberto Exp roberto $
 */
 
 
@@ -21,6 +21,7 @@ typedef unsigned int lua_Object;
 
 lua_Object     lua_setfallback		(char *event, lua_CFunction fallback);
 void           lua_setintmethod	(int tag, char *event, lua_CFunction method);
+void           lua_getintmethod	(int tag, char *event);  /* out: method */
 void           lua_seterrormethod (lua_CFunction method);
 
 int            lua_newtag		(void);

+ 8 - 1
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.91 1997/04/02 17:44:18 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 3.92 1997/04/02 22:52:42 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
@@ -656,6 +656,13 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback)
   return (Ref(top-1));
 }
 
+void lua_getintmethod (int tag, char *event)
+{
+  lua_pushnumber(tag);
+  lua_pushstring(event);
+  do_unprotectedrun(luaI_getintmethod, 2, 1);
+}
+
 void lua_setintmethod (int tag, char *event, lua_CFunction method)
 {
   lua_pushnumber(tag);