![]() |
Show Changes |
![]() |
|
![]() |
Recent Changes |
![]() |
Subscriptions |
![]() |
Lost and Found |
![]() |
Find References |
![]() |
Rename |
![]() |
Administration Page |
![]() |
Topic Locks |
Search |
History
10/4/2007 7:57:49 PM |
-66.249.2.51 |
5/30/2007 10:55:00 AM |
-83.237.111.118 |
5/28/2007 6:48:15 AM |
-69.136.148.27 |
10/18/2006 6:51:26 AM |
-62.5.232.130 |
10/17/2006 11:27:35 PM |
-62.5.232.130 |
![]() |
List all versions |
#include <stdio.h> #include <stdarg.h> #include <sqplus.h> class Vector3 { public: float x, y, z; }; class A { public: Vector3 v; Vector3 get() {return v;} Vector3& getRef() {return v;} Vector3* getPtr() {return &v;} }; static A a; A* get_a() { return &a; } DECLARE_INSTANCE_TYPE(Vector3); DECLARE_INSTANCE_TYPE(A); static int getV(HSQUIRRELVM v) { Vector3 vec = {1,2,3}; return SqPlus::ReturnCopy(v, vec); } void printfunc(HSQUIRRELVM v, const SQChar *s, ...) { va_list arglist; va_start(arglist, s); vprintf(s, arglist); va_end(arglist); } const char *code = "\ print(\"main flow\\n\")\n\ local a = get_a()\n\ ::v <- null\n\ v = a.getPtr()\n\ v.x = 234\n\ v = a.getRef()\n\ v.x = 234\n\ v = a.get()\n\ v.x = 234\n\ print(\"main flow end\\n\")\n\ function thread_func() {\n\ print(\"thread start\\n\")\n\ local a = get_a()\n\ print(\"trying getPtr\\n\")\n\ v = a.getPtr()\n\ v.x = 234\n\ print(\"trying getRef\\n\")\n\ v = a.getRef()\n\ v.x = 234\n\ print(\"trying get\\n\")\n\ v = a.get()\n\ v.x = 234\n\ print(\"thread end\\n\")\n\ }\n\ local coro = ::newthread(thread_func)\n\ coro.call()\n\ "; int main() { SquirrelVM::Init(); sq_setprintfunc(SquirrelVM::GetVMPtr(), printfunc); SqPlus::SQClassDef<Vector3>("Vector3") .var(&Vector3::x, "x") .var(&Vector3::y, "y") .var(&Vector3::z, "z") ; SqPlus::SQClassDef<A>("A") .var(&A::v, "v") .func(&A::get, "get") .func(&A::getRef, "getRef") .func(&A::getPtr, "getPtr") ; SqPlus::RegisterGlobal(get_a, "get_a"); SquirrelObject inst = SquirrelVM::CompileBuffer(code); SquirrelVM::RunScript(inst); SquirrelVM::Shutdown(); return 0; }
When program is run it produces the following output:
main flow main flow end thread start trying getPtr trying getRef AN ERROR HAS OCCURED [the index doesn't exist] CALLSTACK *FUNCTION [main()] console_buffer line [26] LOCALS [coro] THREAD [a] INSTANCE [this] TABLE
This means that fields of variable returned by SqPlus::ReturnCopy is inaccessible when this variable is passed to script from thread. Variables returned by pointer or outside of thread work ok.
It seems that there is a problem in ReturnCopy() with type tags or some issue with SqPlus having global VM handle while threads are also HSQUIRRELVMs.