Bookstore

Recent

Author Topic: using mustapas from leledumbo inside a DLL  (Read 422 times)

mtournay

  • Jr. Member
  • **
  • Posts: 58
using mustapas from leledumbo inside a DLL
« on: February 18, 2020, 05:56:32 pm »
Hello

I try to use https://github.com/leledumbo/mustapas from leledumbo but it seems to be not working from a dll, same code from a simple console program is functionnal.

When I try to use parameters, output stream is empty. After some investigations, i found that
Code: [Select]
  AssignStream(Output,Result);
  Rewrite(Output);
and
Code: [Select]
  Write(Output,Value);               

is disfunctionnal : when I write directly in the stream,
Code: [Select]
  result.Write(value[1], length(value));
output stream is quite good (there's some other problems I believe related to input stream and I see \r\n string at each line)

does someone already had this issue ?
laz 2.06 32b - fpc 3.04 32b - win10 64b

mtournay

  • Jr. Member
  • **
  • Posts: 58
Re: using mustapas from leledumbo inside a DLL
« Reply #1 on: February 19, 2020, 09:07:03 am »
Hi all

I just forked mustapas. The code does not use iostream anymore and run correctly from DLL.

https://github.com/mtournay/mustapas
laz 2.06 32b - fpc 3.04 32b - win10 64b

devEric69

  • Sr. Member
  • ****
  • Posts: 254
Re: using mustapas from leledumbo inside a DLL
« Reply #2 on: February 19, 2020, 09:32:15 am »
Your improvements (thanks for sharing) can't be "push"ed in the original leledumbo/mustapas GitHut?
use: Linux 64 bits (Ubuntu 18.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

mtournay

  • Jr. Member
  • **
  • Posts: 58
Re: using mustapas from leledumbo inside a DLL
« Reply #3 on: February 19, 2020, 09:40:56 am »
Hi

Before asking for PR, I would like to discuss with leledumbo about it (I'd like to know why at first he use iostream)
laz 2.06 32b - fpc 3.04 32b - win10 64b

devEric69

  • Sr. Member
  • ****
  • Posts: 254
Re: using mustapas from leledumbo inside a DLL
« Reply #4 on: February 19, 2020, 09:54:07 am »
That's for sure: leledumbo is the only one who can decide if your improvements can be "push"ed in his GitHub.
==>All I wanted to say, is that it's always better to avoid the fragmentation of a code that provides an evolution of the same functionality, as far as it is possible.
use: Linux 64 bits (Ubuntu 18.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Thaddy

  • Hero Member
  • *****
  • Posts: 9809
Re: using mustapas from leledumbo inside a DLL
« Reply #5 on: February 19, 2020, 10:26:10 am »
I don't think avoiding iostream is a good thing, but I leave it up to Leledumbo to decide.
Reason being that under Linux everything is a file and the original code seems to be designed with that in mind..
It may be that a shared library should be notified of the IO handles in the main program, though.
I can see that point if that is what you mean.
« Last Edit: February 19, 2020, 10:28:12 am by Thaddy »
I am more like donkey than shrek

mtournay

  • Jr. Member
  • **
  • Posts: 58
Re: using mustapas from leledumbo inside a DLL
« Reply #6 on: February 19, 2020, 10:57:13 am »
You both are right

And that's why i didn't PR for now :)

both codes are functionnal, and we have to decide if we reunite with a define with/without iostream (or any other solution) or leave both library.

I don't like the idea of two libraries : i believe I 'm gonna need conditionnal sections, inverted, ... so IF I improve the code, it's better for everyone if there's only one unit
laz 2.06 32b - fpc 3.04 32b - win10 64b

Roland57

  • New Member
  • *
  • Posts: 38
Re: using mustapas from leledumbo inside a DLL
« Reply #7 on: February 19, 2020, 01:01:39 pm »
Hello!

I just discover Mustache. Could someone be kind enough to provide an usage example?

Regards.

Roland

mtournay

  • Jr. Member
  • **
  • Posts: 58
Re: using mustapas from leledumbo inside a DLL
« Reply #8 on: February 19, 2020, 02:33:48 pm »
1. create a file somewhere. inside this file, put
Code: [Select]
hello {{name}}!2. load this file in a stream
3. create a json object with {name: "world"}
4. call mustapas.render and get result in third param
5. put result where you want (screen, http result, ...)

here is a sample code

Code: [Select]
program test_mustache;

uses classes, fpjson, mustapas;

var
  input: TFileStream;
  output: TStringStream;
  params: TJSONObject;

begin
  input := TFileStream.Create('__path__to_your_file', fmOpenRead);
  output:= TStringStream.Create('');
  params := TJSONObject.Create(['name', 'world']);

  Render(input, params, output);
  writeln(output.DataString);

  params.free;
  input.free;
  output.free;
end.

more info on mustache https://mustache.github.io/mustache.5.html
laz 2.06 32b - fpc 3.04 32b - win10 64b

Roland57

  • New Member
  • *
  • Posts: 38
Re: using mustapas from leledumbo inside a DLL
« Reply #9 on: February 19, 2020, 02:55:53 pm »
@mtournay

Thank you.  :)