Posted to tcl by miguel at Sun Jan 06 16:07:19 GMT 2008view raw

  1. Tcl_Obj *nsentPtr;
  2. int entnum;
  3. gentity_t *ent;
  4. char *numchar;
  5. int result;
  6. Tcl_Obj *resPtr;
  7.  
  8. if (objc != 3) {
  9. Tcl_WrongNumArgs(interp, 1, objv, "varName entNum");
  10. return TCL_ERROR;
  11. }
  12. // here I get the entity from it's number: actually, JUST CHECK THAT IT EXISTS!
  13. result = Tcl_GetIntFromObj(interp, objv[2], &entnum);
  14. if (result != TCL_OK) {
  15. return result;
  16. }
  17. ent = &g_entities[entnum]; // HOW DO YOU KNOW IT EXISTS??? Buffer overflow?
  18. // 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 ? :/
  19. // DO NOT STORE THE POINTER (yet?), store the number: eg, '::ent314'
  20. nsentPtr = Tcl_NewStringObj("::ent", -1);
  21. Tcl_AppendObjToObj(nsentPtr, objv[2]);
  22. resPtr = Tcl_ObjSetVar2(interp, objv[1], NULL, nsentPtr, 0);
  23. if (resPtr) {
  24. Tcl_SetObjResult(interp, resPtr);
  25. return TCL_OK;
  26. } else {
  27. return TCL_ERROR;
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34. // This is how I make the entity's namespace :
  35.  
  36. // MODIFY AS ABOVE TO CREATE THE NAMESPACE NAMED ::ent314 for entity number 314
  37. int Entity_Init()
  38. {
  39. Tcl_Namespace *nsPtr;
  40.  
  41. nsPtr = Tcl_CreateNamespace(tclevent, "ent", NULL, NULL);
  42. if (nsPtr == NULL) {
  43. return TCL_ERROR;
  44. }
  45.  
  46. Tcl_CreateObjCommand(tclevent, "ent::get::health", Entity_GetHealth, NULL, NULL);
  47.  
  48. }