Author Topic: MY-BASIC  (Read 84729 times)

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #180 on: February 29, 2016, 06:02:11 pm »
I've added some new features to MY-BASIC:

1. A new keyword "ME" to MY-BASIC to represent a class instance itself inside its scope
2. Multi-line comment support by surrounding comment lines with "'[" and "']"

See an example below:

Code: Text
  1. class clz
  2.         var name = "Clz"
  3.         def tostring()
  4.                 return name ' Returns the "name"
  5.         enddef
  6.         def foo()
  7.                 print me; ' It will use the overridden "tostring"
  8.         enddef
  9. endclass
  10. c = new(clz)
  11. c.name = "Clz (Cloned)"
  12. clz.foo()
  13. c.foo()
  14. '[ Multi-line comment
  15. print "Won't print";
  16. print "Won't print neither";
  17. ']
  18. print "End";
  19.  

@John, Could you add "ME", "'[", "']", and triple dots "..." to the MB code shader? And is it possible to tell the shader the exact type of an identifier to color it, eg. identifiers after "class", "def", and comments between "'[" and "']", it's better if they could be processed distinctively from normal symbols.

@Markus, Removing the console window is friendly for most Windows guys, but it's still necessary when debugging a script, could you give an option to allow user to open a console window? Eg. adding a "console" statement. FYI. this is a sample to create a console window for GUI based applications on Windows http://stackoverflow.com/a/23457341/609345.
« Last Edit: February 29, 2016, 10:45:18 pm by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #181 on: February 29, 2016, 08:03:17 pm »
Have peek at the GeSHi Project Site for the options. Attached is the current mb.php being used. I think the brackets and periods should go under the symbols section. You and Markus should work together on this and come up with a color scheme you like. You can do some pretty cool stuff with the definition file and making your code readable. Download the package and look at the existing .php language definition files as a guide.

« Last Edit: March 01, 2016, 02:04:04 am by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #182 on: March 01, 2016, 02:14:52 am »
Sure, it looks worth studying.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #183 on: March 01, 2016, 03:25:01 am »
I would let Markus take the lead on this as he has a SMF forum he could try it on before giving me the final definition file. The point I was trying to make is that you guys should at least agree on a color scheme and how specialized syntax is dealt with. I'm sure Markus will impress us.


wangrenxin

  • Guest
Re: MY-BASIC
« Reply #184 on: March 01, 2016, 10:15:00 pm »
Hi,

I've added a new sample for MY-BASIC, YARD (Yet Another RPG Dungeon), at https://github.com/paladin-t/my_basic/tree/master/sample/yard. In which I used new features I've implemented these months.

Have fun.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #185 on: March 03, 2016, 01:26:19 am »
I noticed you added a reset argument to mb_load_str.

I'm not sure how the game is suppose to work as I'm not a gamer. Q doesn't seem to quit.

Code: Script BASIC
  1. DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
  2. DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
  3. DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
  4. DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
  5. DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
  6. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  7.  
  8. mb_code = """
  9. import "level.bas"
  10. import "player.bas"
  11.  
  12. print "Welcome to Yet Another RPG Dungeon!";
  13.  
  14. level.create()
  15. _role = new(player)
  16. _role.init(10, 2, 1)
  17. _role.dead_handler = lambda (_)
  18. (
  19.         print "- You are dead";
  20.         level.status = game_status.lose
  21. )
  22. level.start(_role)
  23. _turn = 1
  24. while _role.alive
  25.         print "[----  Turn ", _turn, ", HP ", _role.hp, ", ATK ", _role.atk, "  ----]";
  26.         level.format()
  27.         input _i$
  28.         cls()
  29.         if level.update(_i$) then
  30.                 _turn = _turn + 1
  31.         endif
  32. wend
  33. level.format()
  34. """
  35. mb_init()
  36. mb_open()
  37. mb_load_str(mb_code)
  38. mb_run()
  39. mb_close()
  40. mb_dispose()
  41.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mb_dungeon.sb
Welcome to Yet Another RPG Dungeon!
[----  Turn 1, HP 10, ATK 2  ----]
<0, 0>
[Operations]
  E: Go east
  Q: Quit game


« Last Edit: March 03, 2016, 01:33:27 am by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #186 on: March 03, 2016, 03:29:03 am »
I noticed you added a reset argument to mb_load_str.

Yes, pass with true for most cases.
I'm always cautious to change the API, but it's easy to get wrong with multi-line comments if I didn't add this parameter.

I'm not sure how the game is suppose to work as I'm not a gamer. Q doesn't seem to quit.

I forgot to mention pressing enter after chosen a command.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #187 on: March 03, 2016, 08:26:01 am »
Quote
I forgot to mention pressing enter after chosen a command.

Tried that. No commands seem to work.

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #188 on: March 03, 2016, 11:04:06 pm »
@John, It accepts lower case command only, I've fixed this issue by checking both lower and upper case command input.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #189 on: March 03, 2016, 11:30:46 pm »
Not working and unpredictable and it maxes out my CPU(s).
« Last Edit: March 03, 2016, 11:35:04 pm by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #190 on: March 04, 2016, 01:27:38 am »
Not working and unpredictable and it maxes out my CPU(s).

So sad, it works fine on my Windows. I'll check it on Linux later.

But one odd thing is MB is single threaded, how could it burn both of your CPU cores to 100%...

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #191 on: March 04, 2016, 02:10:25 am »
Quote
But one odd thing is MB is single threaded, how could it burn both of your CPU cores to 100%...

Core leak.  :)

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #192 on: March 11, 2016, 03:59:37 am »
@John, it works fine with my Windows, OSX and Linux (Raspbian for RasPi), could you provide more detailed information for the segment fault?

@All, I've added a short Interop with C# wiki.

Offline John

  • Forum Support / SB Dev
  • Posts: 3046
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #193 on: March 11, 2016, 09:51:01 pm »
My gut was right and Script BASIC is seeing your include as its include. What makes me smile is I didn't get a pre-run syntax error loading MyBASIC code.

I think this is a bug in Script BASIC as it interprets include if the first statement on the line as its own and ignores that it is part of a multi-line string.  :-\

The problem is the included code was inside the MyBASIC code block so MyBASIC was freaking out on multiple sets of the same functions.


jrs@laptop:~/sb/sb22/mybasic$ scriba dbgcon.sb mb_dungeon.sb
Application: ScriptBasic Remote Debugger - Linux
Version: 1.0
Source-File-Count: 9
Source-File: mb_dungeon.sb
Source-File: level.bas
Source-File: goal.bas
Source-File: entity.bas
Source-File: map.bas
Source-File: utils.bas
Source-File: monster.bas
Source-File: npc.bas
Source-File: player.bas
Line: 1
->


« Last Edit: March 12, 2016, 05:05:38 pm by John »

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #194 on: March 14, 2016, 12:37:29 am »
Does SB take the import "xxx" as its own include? I'm afraid there's no better solution than changing the import word in MB or changing in SB.  :-\