Comments (14)
Anything that returns a SharedPtr would require correct reference counting between C++ and the script language. This is natural to AngelScript but to my knowledge tolua++ does not support it. Therefore anything that can't return just a raw pointer has not been exposed to Lua as of now.
@aster2013 may have further insight on the matter.
from urho3d.
Thanks for the quick answer.
I will try to watch syntax for AngelScript.
from urho3d.
I thought you can pass a raw pointer as int between C++ and tolua++?
from urho3d.
Raw pointers are being passed OK, that's not the problem. The problem is that MakeHttpRequest expects the receiver of the SharedPtr to properly reference count the object and release it when done. As far as I understand, unmodified tolua++ has no facility for this. You could cheat and increment the reference count, let the original SharedPtr expire, and return the raw pointer to Lua, but this would leak memory for the remainder of the program.
from urho3d.
there is __gc method on lua metatables that gets called on destruction.
from urho3d.
Tolua++ can bind template to lua, But I have not test is fully.
from urho3d.
Sorry, as I know tolua++ can not support shared pointer, you'd better use raw pointer with it.
from urho3d.
I just realized that MakeHttpRequest() is pretty much only a redundant wrapper. In Lua one could just simply create a new HttpRequest object, as it is self-sufficient. It doesn't even need a Context pointer.
from urho3d.
I have add SharedPtr support in Lua, Please checkout the code for test.
from urho3d.
Nice! I'll test; the solution seems good at least for this case. What we're missing is a general robust solution that would understand the relationship between RefCounted subclasses and their SharedPtr's or WeakPtr's, but that's a lot harder to encode into the bindings.
from urho3d.
Hello,
I pull last code in master and I try to use MakeHttpRequest from lua, but I don't know how to read the response. The example I tried are:
require "LuaScripts/Utilities/Sample"
local http
function Start()
-- Execute the common startup for samples
SampleStart()
SubscribeToEvents()
http = GetNetwork():MakeHttpRequest('http://google.com','GET',{},"")
end
function SubscribeToEvents()
-- Subscribe HandleUpdate() function for processing update events
SubscribeToEvent("Update", "HandleUpdate")
end
function HandleUpdate(eventType, eventData)
print(http:GetState(),http:GetAvailableSize(),"\n")
if http:GetAvailableSize()>0 then
-- how read?
end
end
thanks in advance
from urho3d.
The bulk read function ie. plain Read() is not exposed to Lua (yet) but you can use the rest of the Deserializer API, like ReadUByte() to read one byte at a time, or ReadLine() for text.
from urho3d.
Now SharedPtr may have problem to convert to Deserializer.
from urho3d.
I tried with ReadUByte() at previous sample
-- same as previous sample
function HandleUpdate(eventType, eventData)
if http:GetAvailableSize()>0 then
print(http:ReadUByte())
end
end
This sample crash with Bus error: 10 on OSX 10.8.5.
With ReadLine()
function HandleUpdate(eventType, eventData)
if http:GetAvailableSize()>0 then
print(http:ReadLine())
end
end
Nothing is readed
For last, I try to add a function ReadByteP() that use Read() and It works
diff --git a/Source/Engine/Network/HttpRequest.cpp b/Source/Engine/Network/HttpRequest.cpp
--- a/Source/Engine/Network/HttpRequest.cpp
+++ b/Source/Engine/Network/HttpRequest.cpp
@@ -193,6 +193,13 @@ void HttpRequest::ThreadFunction()
}
}
+unsigned char HttpRequest::ReadByteP()
+{
+ unsigned char b;
+ this->Read(&b,1);
+ return b;
+}
+
unsigned HttpRequest::Read(void* dest, unsigned size)
{
mutex_.Acquire();
diff --git a/Source/Engine/Network/HttpRequest.h b/Source/Engine/Network/HttpRequest.h
--- a/Source/Engine/Network/HttpRequest.h
+++ b/Source/Engine/Network/HttpRequest.h
@@ -56,6 +56,8 @@ public:
virtual unsigned Read(void* dest, unsigned size);
/// Set position from the beginning of the stream. Not supported.
virtual unsigned Seek(unsigned position) { return position_; }
+
+ unsigned char ReadByteP();
/// Return URL used in the request.
const String& GetURL() const { return url_; }
diff --git a/Source/Extras/LuaScript/pkgs/Network/HttpRequest.pkg b/Source/Extras/LuaScript/pkgs/Network/HttpRequest.pkg
--- a/Source/Extras/LuaScript/pkgs/Network/HttpRequest.pkg
+++ b/Source/Extras/LuaScript/pkgs/Network/HttpRequest.pkg
@@ -16,6 +16,8 @@ class HttpRequest : public Deserializer
HttpRequestState GetState() const;
unsigned GetAvailableSize() const;
bool IsOpen() const;
+
+ unsigned char ReadByteP();
tolua_readonly tolua_property__get_set String URL;
tolua_readonly tolua_property__get_set String verb;
And the modified handle
-- ...
local str = ""
function HandleUpdate(eventType, eventData)
while http:GetAvailableSize()>0 do
str = str .. string.char(http:ReadByteP())
end
print(str)
end
Thanks for your support.
from urho3d.
Related Issues (20)
- Lua Sample 12 coroutine usage HOT 1
- Crash in UI::Update() HOT 3
- ios crash HOT 1
- Dropping 32 bit support HOT 6
- Dropping DirectX 9 support
- Segfault on SetModel in headless mode HOT 4
- Dropping macOS support HOT 4
- DropDownList displayed element is not vertically centered HOT 1
- SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS always 0 when build 32-bit version of the engine on 64-bit Linux Mint HOT 5
- Non-Master AnimatedModel Removing Skeleton
- Dot at the end of a doxygen comment HOT 7
- Error building on Windows + MSYS + MinGW-W64 HOT 1
- Dockerize-web broken HOT 2
- Not building on arch Linux. HOT 3
- Toolset Visual Studio 2022 (v143) поломан HOT 12
- Не работает превью ресурсов в редакторе HOT 13
- Использовать нижний регистр для файлов HOT 2
- Build failes on (Void) Linux with make HOT 6
- -gl2 поломан
- Малая понятность CMake скриптов
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urho3d.