hchunhui / librime-lua

Extending RIME with Lua scripts
BSD 3-Clause "New" or "Revised" License
293 stars 43 forks source link

KeyEvent() constructor now can also take a code and a modifier #321

Closed fxliang closed 4 months ago

shewer commented 4 months ago

可以綁在一起嗎

int raw_make(lua_State *L) {
   an<T> res; // nil
   int n = lua_gettop(L);  
   if ( n == 1 )
       res =  New<T>(string(lua_tostring(L, 1));
    else if (n > 1)
       res = New<T>( lua_tointeger(L, 1), lua_tointeger(L, 2));

     LuaType<an<T>>::pushdata(L, res);
     return 1;
 }

KeyEvent( string) KeyEvent( int code, int modifier)

fxliang commented 4 months ago

可以綁在一起嗎

int raw_make(lua_State *L) {
   an<T> res; // nil
   int n = lua_gettop(L);  
   if ( n == 1 )
       res =  New<T>(string(lua_tostring(L, 1));
    else if (n > 1)
       res = New<T>( lua_tointeger(L, 1), lua_tointeger(L, 2));

     LuaType<an<T>>::pushdata(L, res);
     return 1;
 }

KeyEvent( string) KeyEvent( int code, int modifier)

试了不行

shewer commented 4 months ago

我試可以的 , KeyEvent 要重定義

  int raw_make(lua_State *L) {
    an<T> res;
    int n = lua_gettop(L);
    if (n == 1)
      res = New<T>( string(lua_tostring(L, 1)) );
    else if (n > 1)
      res = New<T>(lua_tointeger(L, 1), lua_tointeger(L, 2));

    LuaType<an<T>>::pushdata(L, res);
    return 1;
  }

  static const luaL_Reg funcs[] = {
    { "KeyEvent", raw_make},
    { NULL, NULL },
  };

image

fxliang commented 4 months ago

原来是我打开方式不对(加了WRAP...)