Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <squirrel.h>
  4. #include <sqstdio.h>
  5. #include <sqstdaux.h>
  6. #ifdef _MSC_VER
  7. #pragma comment (lib ,"squirrel.lib")
  8. #pragma comment (lib ,"sqstdlib.lib")
  9. #endif
  10. #ifdef SQUNICODE
  11. #define scvprintf vwprintf
  12. #else
  13. #define scvprintf vprintf
  14. #endif
  15. void printfunc(HSQUIRRELVM v, const SQChar *s, ...)
  16. {
  17. va_list arglist;
  18. va_start(arglist, s);
  19. scvprintf(s, arglist);
  20. va_end(arglist);
  21. }
  22. void call_foo(HSQUIRRELVM v, int n,float f,const SQChar *s)
  23. {
  24. SQInteger top = sq_gettop(v); //saves the stack size before the call
  25. sq_pushroottable(v); //pushes the global table
  26. sq_pushstring(v,_SC("foo"),-1);
  27. if(SQ_SUCCEEDED(sq_get(v,-2))) { //gets the field 'foo' from the global table
  28. sq_pushroottable(v); //push the 'this' (in this case is the global table)
  29. sq_pushinteger(v,n);
  30. sq_pushfloat(v,f);
  31. sq_pushstring(v,s,-1);
  32. sq_call(v,4,SQFalse,SQTrue); //calls the function
  33. }
  34. sq_settop(v,top); //restores the original stack size
  35. }
  36. int main(int argc, char* argv[])
  37. {
  38. HSQUIRRELVM v;
  39. v = sq_open(1024); // creates a VM with initial stack size 1024
  40. //sq_pushroottable(v); //push the root table were to register the lib function
  41. //sqstd_register_iolib(v);
  42. sqstd_seterrorhandlers(v); //registers the default error handlers
  43. sq_setprintfunc(v, printfunc); //sets the print function
  44. sq_pushroottable(v); //push the root table(were the globals of the script will be stored)
  45. if(SQ_SUCCEEDED(sqstd_dofile(v, _SC("test.nut"), SQFalse, SQTrue))) // also prints syntax errors if any
  46. {
  47. call_foo(v,1,2.5,_SC("teststring"));
  48. }
  49. sq_pop(v,1); //pops the root table
  50. sq_close(v);
  51. return 0;
  52. }