Check-in [4c5284048d]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added exists command as a quicker and easier way to find symbols than info
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:4c5284048dac6a966a979dac77b986bb3ce589f64c9790e144b6481cebbe685c
User & Date: grable 2018-11-01 16:43:02
Context
2018-11-01
18:44
simplified jimff_getcallback() and jimff_getlibrary(), also added update argument to update the object if string search succeeds check-in: 239dbfb881 user: grable tags: trunk
16:43
added exists command as a quicker and easier way to find symbols than info check-in: 4c5284048d user: grable tags: trunk
05:05
fixed no args to wrap/unwrap commands check-in: df58e94263 user: grable tags: trunk
Changes

Changes to jimff-commands.c.

29
30
31
32
33
34
35

36
37
38



39
40
41
42
43
44
45
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
....
1352
1353
1354
1355
1356
1357
1358
1359
1360






































































1361
1362
1363
1364
1365
1366
1367
....
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
	_( pointer,		fn_context_pointer,	NULL )			\
	_( unwrap,		fn_pointer_unwrap,	NULL )			\
	_( wrap,		fn_pointer_wrap,		NULL )			\
	_( gets,			fn_pointer_gets,			NULL )			\
	_( read,			fn_pointer_read,		NULL )			\
	_( write,		fn_pointer_write,		NULL )			\
	_( copy,			fn_pointer_copy,		NULL )			\

	__jimff_the_info_command(_)

// macros for use by __jimff_commands()



#define __jimff_create_command( _name, _cmdfn, _freefn)								\
	({ snprintf( buffer, sizeof(buffer), "%s::" #_name, ctx->name);					\
		Jim_CreateCommand( ctx->interp, buffer, (_cmdfn), ctx, (_freefn)); });

#define __jimff_delete_command( _name, _cmdfn, _freefn)				\
	({ snprintf( buffer, sizeof(buffer), "%s::" #_name, ctx->name);	\
		Jim_DeleteCommand( ctx->interp, buffer); });
................................................................................
		}																												\
		printf( "  %-*s %.*s\n",  strlen(ctx->name) + 11, buffer,								\
											strlen(_errstr) - _argsoffs - 1, _errstr + _argsoffs);	\
		Jim_DecrRefCount( ctx->interp, _nameobj); });

static int fn_context_new( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_free( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_load( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_import( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_callback( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_pointer( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_unwrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_wrap( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_gets( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_read( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_write( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_pointer_copy( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
#ifndef JIMFF_DISABLE_INFO_COMMAND
static int fn_context_info( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
#endif
static int fn_symbol_call( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_symbol_set( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);


// called when renaming to "" or calling "$ns::free"
static void free_ctx( Jim_Interp* interp, void* privdata) {
	struct jimff_context* ctx = privdata;
	char buffer[128];
	struct jimff_assoc* assoc;
	int index;	
................................................................................
				numcb++;
				break;
		}
	}
	return str;
}

//TODO: either need to rethink the "info" command since its getting overloaded and only returns lists of tings.
//TODO: or add a companion command like "exists" for finding stuff without searching for it through what info returns.






































































static int fn_context_info( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	static const char * const infomodes[] = { "-help", "-libraries", "-symbols", "-functions", "-variables", "-callbacks", NULL };
	enum { INFO_HELP, INFO_LIBRARIES, INFO_SYMBOLS, INFO_FUNCTIONS, INFO_VARIABLES, INFO_CALLBACKS };

	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);		
	Jim_Obj* list = NULL;
................................................................................
			argc--;
			argv++;
			gotmode = 1;
		} else {
			mode = INFO_SYMBOLS;
		}
	} else {
		Jim_WrongNumArgs( interp, 1, argv,	"-help | -libraries | -symbols ?library? | -functions ?library? | -variables ?library? | -callbacks"	\
																" ?-typetags | -commands?");
		return JIM_ERR;
	}
	
	if(argc >= 2) {
		if(Jim_CompareStringImmediate( interp, argv[1], "-typetags")) {
			if(mode == INFO_LIBRARIES) {
				Jim_SetResultFormatted( interp, "%#s: -typetags can not be used with -libraries", argv0);







>



>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<


>







 







|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
59
60
61
62
63
64
65













66
67
68
69
70
71
72
73
74
75
....
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
....
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
	_( pointer,		fn_context_pointer,	NULL )			\
	_( unwrap,		fn_pointer_unwrap,	NULL )			\
	_( wrap,		fn_pointer_wrap,		NULL )			\
	_( gets,			fn_pointer_gets,			NULL )			\
	_( read,			fn_pointer_read,		NULL )			\
	_( write,		fn_pointer_write,		NULL )			\
	_( copy,			fn_pointer_copy,		NULL )			\
	_( exists,		fn_context_exists,		NULL )			\
	__jimff_the_info_command(_)

// macros for use by __jimff_commands()
#define __jimff_declare_command( _name, _cmdfn, _freefn)				\
	static int _cmdfn( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
		
#define __jimff_create_command( _name, _cmdfn, _freefn)								\
	({ snprintf( buffer, sizeof(buffer), "%s::" #_name, ctx->name);					\
		Jim_CreateCommand( ctx->interp, buffer, (_cmdfn), ctx, (_freefn)); });

#define __jimff_delete_command( _name, _cmdfn, _freefn)				\
	({ snprintf( buffer, sizeof(buffer), "%s::" #_name, ctx->name);	\
		Jim_DeleteCommand( ctx->interp, buffer); });
................................................................................
		}																												\
		printf( "  %-*s %.*s\n",  strlen(ctx->name) + 11, buffer,								\
											strlen(_errstr) - _argsoffs - 1, _errstr + _argsoffs);	\
		Jim_DecrRefCount( ctx->interp, _nameobj); });

static int fn_context_new( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_context_free( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);













static int fn_symbol_call( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
static int fn_symbol_set( Jim_Interp* interp, int argc, Jim_Obj* const argv[]);
__jimff_commands(__jimff_declare_command);

// called when renaming to "" or calling "$ns::free"
static void free_ctx( Jim_Interp* interp, void* privdata) {
	struct jimff_context* ctx = privdata;
	char buffer[128];
	struct jimff_assoc* assoc;
	int index;	
................................................................................
				numcb++;
				break;
		}
	}
	return str;
}

static int fn_context_exists( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	static const char * const existmodes[] = { "-library", "-symbol", "-function", "-variable", "-callback", NULL };
	enum { EXISTS_LIBRARY, EXISTS_SYMBOL, EXISTS_FUNCTION, EXISTS_VARIABLE, EXISTS_CALLBACK };

	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);
	int mode;
	struct jimff_library* lib = NULL;
	struct jimff_symbol* sym;
	struct jimff_callback* cb;
	int narg = 1;
	
	if(argc >= 2) {
		if(Jim_GetEnum( interp, argv[1], existmodes, &mode, "modes", JIM_ENUM_ABBREV) == JIM_OK) {
			argc--;
			argv++;
		} else {
			mode = EXISTS_SYMBOL;
		}
	} else {
wrongnumargs:
		Jim_WrongNumArgs( interp, 1, argv,	"?-library | -symbol | -function | -variable | -callback? ?library? name");
		return JIM_ERR;
	}
	
	switch(mode) {
		case EXISTS_LIBRARY:
			if(argc != 2) goto wrongnumargs;
			Jim_SetResultBool( interp, jimff_getlibrary( ctx, argv[1]) != NULL);
			return JIM_OK;
		
		case EXISTS_SYMBOL:
		case EXISTS_FUNCTION:
		case EXISTS_VARIABLE:
			if(argc == 3) {
				lib = jimff_getlibrary( ctx, argv[1]);
				if(!lib) goto err_library_not_found;
				narg++;
			} else if(argc != 2) {
				goto wrongnumargs;
			}
			if(!lib) {
				for JIMFF_LIST_EACH( lib, ctx->libs) {
					if(sym = jimff_find_symbol( lib, Jim_String(argv[narg]))) break;
				}
			} else {
				sym = jimff_find_symbol( lib, Jim_String(argv[narg]));
			}
			if(!sym || (mode == EXISTS_FUNCTION && sym->tag != JIMFF_SYM_FUNCTION)
						|| (mode == EXISTS_VARIABLE && sym->tag == JIMFF_SYM_FUNCTION)) goto not_exists;
			break;
			
		case EXISTS_CALLBACK:
			if(argc != 2) goto wrongnumargs;
			cb = jimff_find_callback( ctx, Jim_String(argv[1]));
			if(!cb) goto not_exists;
			break;
	}
	
exists:
	Jim_SetResultBool( interp, 1);
	return JIM_OK;	
	
not_exists:
	Jim_SetResultBool( interp, 0);
	return JIM_OK;
	
err_library_not_found:
	Jim_SetResultFormatted( interp, "%#s: library \"%#s\" not found", argv0, argv[1]);
	return JIM_ERR;
}

static int fn_context_info( Jim_Interp* interp, int argc, Jim_Obj* const argv[]) {
	static const char * const infomodes[] = { "-help", "-libraries", "-symbols", "-functions", "-variables", "-callbacks", NULL };
	enum { INFO_HELP, INFO_LIBRARIES, INFO_SYMBOLS, INFO_FUNCTIONS, INFO_VARIABLES, INFO_CALLBACKS };

	Jim_Obj* argv0 = argv[0];
	struct jimff_context* ctx = Jim_CmdPrivData(interp);		
	Jim_Obj* list = NULL;
................................................................................
			argc--;
			argv++;
			gotmode = 1;
		} else {
			mode = INFO_SYMBOLS;
		}
	} else {
		Jim_WrongNumArgs( interp, 1, argv,	"?-help | -libraries | -symbols ?library? | -functions ?library? | -variables ?library? | -callbacks"	\
																" ?-commands?? ?-typetags?");
		return JIM_ERR;
	}
	
	if(argc >= 2) {
		if(Jim_CompareStringImmediate( interp, argv[1], "-typetags")) {
			if(mode == INFO_LIBRARIES) {
				Jim_SetResultFormatted( interp, "%#s: -typetags can not be used with -libraries", argv0);