Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Config file parser

Author
Message
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 5th Jun 2010 06:35 Edited at: 5th Jun 2010 07:02
I was writing a config file parser for a game I'm making in c++, and I figured i would put it in a library. I then decided to make a dbc library for it.

here is the list of functions:

cfg_New:
Params: 1 String, Name of the config file
returns a new Config parser from the specified file

cfg_NewData:
Params: 2 String/Ptr, DWORD size(or number of characters) of the data in bytes. Returns a new Config parser from the specified data

cfg_Quit:
Params: 1 DWORD, Config parser to close

cfg_GetStr:
Params: 1 DWORD, Config Handle. String Setting name, and a destenation.
returns: the string that was inputed. If the setting doesn't exist, the string is unchanged

cfg_GetInt:
Params: 3 DWORD, Config Handle. String Setting Name. Integer, default value
Returns: The integer value of that setting, or the default value

cfg_GetUint:
Same as above, but with unsigned integer

cfg_GetBool:
Params: 3. DWORD, Config handle. String, Setting name. BOOL(0 or 1) default value
Returns: 0 or 1. The config file should be true, or false. Not 0 or 1

cfg_GetFloat
Doesn't work right now. Working on it.

cfg_GetConfig
Params 2. DWORD, Config handle, String, Setting name
Returns: A new setting handle. See below for explanation

cfg_SettingExist
Params: 2. DWORD, Config handle. String, setting name
Returns: 1 if the setting exists, and 0 if it doesn't

cfg_Open
Params: 2. DWORD, Config handle, String file name
Returns: 1 or 0 specifying success. This will open a config file


The cfg_GetConfig will open a new config handle from a config setting. This means you can essentially build embeded config files. Like this:



This useful for things like controls. here is how I did my config file for the game i'm making:



All settings MUST havea semi-colon after it. The original Config functions, outputed error information to the console, and returned 0 for functions, but DBC doesn't have a console, so I am going to have to find a new error system.

The source, and dll is attached.

Well, I was doing some more testing, and It seems I am having problems with strings. It must have something to do with how they are allocated in dbc. Does anyone have any insight as to how they are allocated/deallocated?

New Site! Check it out \/

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Jun 2010 11:25
Quote: "Well, I was doing some more testing, and It seems I am having problems with strings. It must have something to do with how they are allocated in dbc. Does anyone have any insight as to how they are allocated/deallocated?"

If you aren't using strings through memblocks but are using string variables from DBC (mystring$), keep in mind that the max size is 255 characters. Also plan that C or C++ always use the last character in a char array as a NULL. Anyway, set up the DBC string to it's maximum length with

mystring$=SPACE$(255)

before sending it or using it as a pointer in C. This way there's plenty of memory allocated for it (up to 255 bytes) and C or C++ should end it with a NULL making it variable length upon return (up to a max of 254 characters with 0 at 255)

SPACE$() is a built in command to fill a string with character code 32 the number of times inside the () up to 255.

Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 6th Jun 2010 03:00
Thanks latch! I completely forgot about the string being max of 255! I think my problem was I was doing it like this:

myString$ = "Default Value"
call dll 1,"cfg_GetStr",cfg,"strVal",myString$

which meant the strings length was only 13 characters no matter how big the value of strVal was.

Memblocks might be a good idea. I will see what I can do.

New Site! Check it out \/

Login to post a reply

Server time is: 2024-04-19 15:33:09
Your offset time is: 2024-04-19 15:33:09