Posted to tcl by miguel at Sun Jan 06 16:07:19 GMT 2008view raw
- Tcl_Obj *nsentPtr;
- int entnum;
- gentity_t *ent;
- char *numchar;
- int result;
- Tcl_Obj *resPtr;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "varName entNum");
- return TCL_ERROR;
- }
- // here I get the entity from it's number: actually, JUST CHECK THAT IT EXISTS!
- result = Tcl_GetIntFromObj(interp, objv[2], &entnum);
- if (result != TCL_OK) {
- return result;
- }
- ent = &g_entities[entnum]; // HOW DO YOU KNOW IT EXISTS??? Buffer overflow?
- // ent is the entity's pointer but how to set it in the entPointer in order to get it automatically when a command from the ent namespace is typed ? :/
- // DO NOT STORE THE POINTER (yet?), store the number: eg, '::ent314'
- nsentPtr = Tcl_NewStringObj("::ent", -1);
- Tcl_AppendObjToObj(nsentPtr, objv[2]);
- resPtr = Tcl_ObjSetVar2(interp, objv[1], NULL, nsentPtr, 0);
- if (resPtr) {
- Tcl_SetObjResult(interp, resPtr);
- return TCL_OK;
- } else {
- return TCL_ERROR;
- }
- // This is how I make the entity's namespace :
- // MODIFY AS ABOVE TO CREATE THE NAMESPACE NAMED ::ent314 for entity number 314
- int Entity_Init()
- {
- Tcl_Namespace *nsPtr;
- nsPtr = Tcl_CreateNamespace(tclevent, "ent", NULL, NULL);
- if (nsPtr == NULL) {
- return TCL_ERROR;
- }
- Tcl_CreateObjCommand(tclevent, "ent::get::health", Entity_GetHealth, NULL, NULL);
- }