|
1 | 1 | from contextlib import asynccontextmanager |
2 | 2 | from typing import Optional, List |
3 | 3 |
|
4 | | -from .base import BaseSubAPI, lua_string |
| 4 | +from .base import BaseSubAPI |
| 5 | +from ..lua import LuaExpr, lua_string |
5 | 6 | from ..rproc import boolean, string, integer, nil, array_string, option_string, fact_scheme_dict |
6 | 7 |
|
7 | 8 |
|
|
13 | 14 | }, {}) |
14 | 15 |
|
15 | 16 |
|
16 | | -class BaseHandle(BaseSubAPI): |
| 17 | +class BaseHandle(BaseSubAPI, LuaExpr): |
17 | 18 | def __init__(self, cc, var): |
18 | 19 | super().__init__(cc) |
19 | 20 | self._API = var |
20 | 21 |
|
| 22 | + def get_expr_code(self): |
| 23 | + return self._API |
| 24 | + |
21 | 25 |
|
22 | 26 | class ReadHandle(BaseHandle): |
23 | 27 | async def read(self, count: int) -> Optional[str]: |
@@ -106,12 +110,12 @@ async def open(self, path: str, mode: str): |
106 | 110 | ''' |
107 | 111 | fid = self._cc._new_task_id() |
108 | 112 | var = 'temp[{}]'.format(lua_string(fid)) |
109 | | - await self._cc._send_cmd('{} = fs.open({}, {})'.format( |
| 113 | + await self._cc.eval_coro('{} = fs.open({}, {})'.format( |
110 | 114 | var, *map(lua_string, [path, mode]))) |
111 | 115 | try: |
112 | 116 | yield (ReadHandle if 'r' in mode else WriteHandle)(self._cc, var) |
113 | 117 | finally: |
114 | | - await self._cc._send_cmd('{}.close(); {} = nil'.format(var, var)) |
| 118 | + await self._cc.eval_coro('{}.close(); {} = nil'.format(var, var)) |
115 | 119 |
|
116 | 120 | async def find(self, wildcard: str) -> List[str]: |
117 | 121 | return array_string(await self._send('find', wildcard)) |
|
0 commit comments