Calling Lua from BCX with no DLL dependencies

Started by Quin, April 27, 2025, 10:25:37 AM

Previous topic - Next topic

Quin


MrBcx

Quote from: Quin on May 03, 2025, 06:49:27 PMVery nice!
Out of curiosity, when can we expect the new BCX? I don't have any bugs that I need fixed, but I know they normally get released at the end of the month.


8.2.7 will be released later this month. 

Quin

Very nice!
Out of curiosity, when can we expect the new BCX? I don't have any bugs that I need fixed, but I know they normally get released at the end of the month.

MrBcx

Today I added a few lines of code to BCX 8.2.7 that properly detects and handles
the above edge case, which means that it won't be necessary to edit Basic.bas, as shown
in the workaround in my previous post.

MrBcx

#23
UPDATE:

In my experience, Ed can only be successfully compiled to 32-bit using Pelles C and Lcc-Win32.
And by successfully, I mean the editor works, the menus work,  and we can load and run the many samples
that are included in "Ed.zip" mentioned earlier.

Mingw and Clang can compile Ed but Ed will not function correctly, so don't waste your time trying.

Bcx version 790 and later expanded support for sigil-less variable detection.
One of those detections is incompatible with a dozen similar statements found in \interpreter\Basic.bas.

Load Basic.bas into your favorite code editor and replace the lines that end with:


.sv [0] =  0

to


.sv = "" 

Then you should be able to compile the resulting Ed.c (to 32-bit) using the current version
of BCX
, along with practically any version of Pelles C.








jbk

Quote from: MrBcx on April 30, 2025, 07:11:12 PMI know one person who definitely is not interested in a project like that.
makes me wonder who that person might be  ;D
it compiles with Mingw-64 but the keyboard handling is eratic.
as for embedded interpreter/script engine, if it's embedded then I expect easy interoperability between the host and the interpreter/script engine, otherwise what's the point?

Robert

Quote from: MrBcx on April 30, 2025, 07:11:12 PM
Quote from: Robert on April 30, 2025, 01:03:10 PMHi MrBcx:

Maybe it's time to put Ed to Bed ?

https://bcxbasiccoders.com/smf/index.php?msg=2171

Hi Robert,

That was never more than a toy project, to see if I could incorporate Andreas Gunther's
mini-bcx interpreter into my decades old console based editor.  As I stated in that 2021 thread: 
"The whole thing is still buggy but it mostly works and is full of stuff to learn from."

That part hasn't changed.

If you're suggesting incorporating the mini-bcx interpreter into a scintilla-based editor (like Bed),
that's certainly possible, but without a lot of work, one would need to use the 32-bit scintilla framework
with the current mini-bcx interpreter engine.  Someone might find that to be a fun and interesting project.
I know one person who definitely is not interested in a project like that.

Hi MrBCX:

Still buggy, yes I noticed that on my one attempt; the Code Page 437 box drawing causing Pelles to complain not UTF-8. When I changed the file type to Code Page 437, complaint was not ANSI.

Just for giggles, I will have to dig out my Code Page 437 to UTF-8 converter and see if Ed will at least compile with a substitution of UTF-8 box drawing characters.

Lots to learn from Andreas' interpreter as well.

MrBcx

Quote from: Robert on April 30, 2025, 01:03:10 PMHi MrBcx:

Maybe it's time to put Ed to Bed ?

https://bcxbasiccoders.com/smf/index.php?msg=2171

Hi Robert,

That was never more than a toy project, to see if I could incorporate Andreas Gunther's
mini-bcx interpreter into my decades old console based editor.  As I stated in that 2021 thread: 
"The whole thing is still buggy but it mostly works and is full of stuff to learn from."

That part hasn't changed.

If you're suggesting incorporating the mini-bcx interpreter into a scintilla-based editor (like Bed),
that's certainly possible, but without a lot of work, one would need to use the 32-bit scintilla framework
with the current mini-bcx interpreter engine.  Someone might find that to be a fun and interesting project.
I know one person who definitely is not interested in a project like that.


Robert

Quote from: MrBcx on April 30, 2025, 08:15:04 AM
Quote from: jbk on April 30, 2025, 06:35:16 AMMrBcx
try the following adaptation

'******************************************************
' copying a my_basic variable value to a bcx variable
' attribution:    by mrbcx april 29, 2025
'******************************************************

CONST MB_DOUBLE_FLOAT                        ' make the my_basic default double instead of single
#include "my_basic.c"

DIM myvar AS DOUBLE                          ' this is the receiving bcx variable
DIM script AS STRING
DIM value AS mb_value_t
DIM bas AS struct mb_interpreter_t PTR

script  = "INPUT " + WRAP$("enter a number ")+ ",PI"                           + CRLF$
script += "PI=PI*PI"                                                           + CRLF$
script += "PRINT " + WRAP$("the number squared = ")+ ",PI;"                    + CRLF$

mb_init()
mb_open(&bas)
mb_load_string(bas, script, TRUE)
mb_run(bas, TRUE)
mb_debug_get(bas, "PI", &value)              ' my_basic vars (like pi in this example) must be passed in uppercase
myvar = value.value.float_point

mb_close(&bas)
mb_dispose()

PRINT myvar

PAUSE
Quoteenter a number 12
the number squared = 144
 7.11454530011395E-322
however if you enter say "12.1" then you get a correct printout
I am seriously disliking My_Basic, it needs to go to the trash and forget about it


JB - I'm inclined to agree with you.

I don't know how well or poorly MB performs as a REPL but as a script language, it stinks.

Fortunately, BCX users needing to incorporate BCX code and scripting still have easy access to VBScript.

Hi MrBcx:

Maybe it's time to put Ed to Bed ?

https://bcxbasiccoders.com/smf/index.php?msg=2171

MrBcx

#18
Quote from: jbk on April 30, 2025, 06:35:16 AMMrBcx
try the following adaptation

'******************************************************
' copying a my_basic variable value to a bcx variable
' attribution:    by mrbcx april 29, 2025
'******************************************************

CONST MB_DOUBLE_FLOAT                        ' make the my_basic default double instead of single
#include "my_basic.c"

DIM myvar AS DOUBLE                          ' this is the receiving bcx variable
DIM script AS STRING
DIM value AS mb_value_t
DIM bas AS struct mb_interpreter_t PTR

script  = "INPUT " + WRAP$("enter a number ")+ ",PI"                           + CRLF$
script += "PI=PI*PI"                                                           + CRLF$
script += "PRINT " + WRAP$("the number squared = ")+ ",PI;"                    + CRLF$

mb_init()
mb_open(&bas)
mb_load_string(bas, script, TRUE)
mb_run(bas, TRUE)
mb_debug_get(bas, "PI", &value)              ' my_basic vars (like pi in this example) must be passed in uppercase
myvar = value.value.float_point

mb_close(&bas)
mb_dispose()

PRINT myvar

PAUSE
Quoteenter a number 12
the number squared = 144
 7.11454530011395E-322
however if you enter say "12.1" then you get a correct printout
I am seriously disliking My_Basic, it needs to go to the trash and forget about it


JB - I'm inclined to agree with you.

I don't know how well or poorly MB performs as a REPL but as a script language, it stinks.

Fortunately, BCX users needing to incorporate BCX code and scripting still have easy access to VBScript.

jbk

MrBcx
try the following adaptation

'******************************************************
' copying a my_basic variable value to a bcx variable
' attribution:    by mrbcx april 29, 2025
'******************************************************

CONST MB_DOUBLE_FLOAT                        ' make the my_basic default double instead of single
#include "my_basic.c"

DIM myvar AS DOUBLE                          ' this is the receiving bcx variable
DIM script AS STRING
DIM value AS mb_value_t
DIM bas AS struct mb_interpreter_t PTR

script  = "INPUT " + WRAP$("enter a number ")+ ",PI"                           + CRLF$
script += "PI=PI*PI"                                                           + CRLF$
script += "PRINT " + WRAP$("the number squared = ")+ ",PI;"                    + CRLF$

mb_init()
mb_open(&bas)
mb_load_string(bas, script, TRUE)
mb_run(bas, TRUE)
mb_debug_get(bas, "PI", &value)              ' my_basic vars (like pi in this example) must be passed in uppercase
myvar = value.value.float_point

mb_close(&bas)
mb_dispose()

PRINT myvar

PAUSE
Quoteenter a number 12
the number squared = 144
 7.11454530011395E-322
however if you enter say "12.1" then you get a correct printout
I am seriously disliking My_Basic, it needs to go to the trash and forget about it

jos

Thanks again MrBCX,
Sorry for not thinking further!
I was blown away by how easy you showed the implementation of a problem that I thought was really tricky.
Of course you need to get values in and get the results out.

I feel like I will get use out of this when everything works for me. My idea is that I want users to be able to put simple values/calculations in an invoicing program when entering/leaving a field. But I see endless uses..

I guess I don't really understand how powerful and simple BXC is!

Finally a compliment to your pedagogical order to always explain and describe how you do it.

Thanks again



jbk

thanks MrBcx
but I have been unsuccessful in assigning a value to a my_basic variable and then run a script using that value

Quin

Very cool stuff, MrBcx! Thanks as always for your incredible wizardry :D

MrBcx

This updated example now shows how to copy a BCX variable's value to a my_basic variable


'******************************************************
' Copying a my_basic variable value to a BCX variable
' Attribution:    by MrBcx April 29, 2025
'******************************************************
#include "my_basic.c"

CONST MB_DOUBLE_FLOAT                        ' Make the my_basic default DOUBLE instead of SINGLE

DIM MyVar AS DOUBLE                          ' This is the receiving BCX variable
DIM bas AS struct mb_interpreter_t PTR

mb_init()
mb_open(&bas)

mb_load_string(bas, "pi = ATAN(1)*4", TRUE)  ' my_basic FUNCTIONS (like ATAN() in this example) must be passed in UPPERCASE
mb_run(bas, TRUE)

'*******************************
DIM value AS mb_value_t
mb_debug_get(bas, "PI", &value)              ' my_basic vars (like PI in this example) must be passed in UPPERCASE
MyVar = value.value.float_point
PRINT MyVar                                  ' This will print 3.14159265358979   (PI)
'*******************************

'*******************************
MyVar  = 1.23456789                          ' Give MyVar a new value
value.value.float_point = MyVar              ' Copy a BCX variable into a my_basic variable
mb_debug_set(bas, "PI",  value)              ' Store it inside the my_basic "PI" variable
mb_debug_get(bas, "PI", &value)              ' Pull a copy from the "PI" variable and
MyVar = 0                                    ' Sanity check
MyVar = value.value.float_point              ' Store the new value in the BCX variable
PRINT MyVar                                  ' This will print 1.23456789
'*******************************

mb_close(&bas)
mb_dispose()

PAUSE