JSIO.cpp 745 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "JSIO.h"
  5. #include "JSVM.h"
  6. #include <Atomic/IO/File.h>
  7. namespace Atomic
  8. {
  9. static int File_ReadText(duk_context* ctx)
  10. {
  11. duk_push_this(ctx);
  12. File* file = js_to_class_instance<File>(ctx, -1, 0);
  13. String text;
  14. file->ReadText(text);
  15. duk_push_string(ctx, text.CString());
  16. return 1;
  17. }
  18. void jsapi_init_io(JSVM* vm)
  19. {
  20. duk_context* ctx = vm->GetJSContext();
  21. js_class_get_prototype(ctx, "File");
  22. duk_push_c_function(ctx, File_ReadText, 0);
  23. duk_put_prop_string(ctx, -2, "readText");
  24. duk_pop(ctx);
  25. }
  26. }