The Dink Network

DinkC++: An Intro. Article 1

November 15th 2004, 08:50 PM
wizardb.gif
Merlin
Peasant He/Him
 
NOTE: SINCE THIS BOARD SUCKS AND DOESN'T ALLOW AS-TYPED SPACING I HAVE MOVED APPROPRIATE CODE OVER USING PERIODS. <----Like that one.

DinkC++: An Intro
Article 1
==============

Many people ask me "When will Windemere be done", or "Is Windemere dead?", or "What are you doing on Saturday?" (Okay, truthfully, nobody has ever asked me that last one. But you might've already guessed that). Well, I am here not to answer those questions, but rather to answer them like a politician. And no, answering them like a politician rarely constitutes answering the question in my book.

Don't leave yet; more interesting things are to come. I promise.

Windemere has been through many stages, most of which have left me in isolation. I remember my first post at the Dink Network stated that I would rewrite the engine to form a “Dink 2”. I was alone then; like I am now – but that's a story for another day. I was alone then. Several programmers came my way after Seth's sudden decision to release the source code to his engine. That is where I made my first mistake: thinking I could use his code. Wrong. His code was a taint. And I don't mean a taint like a stain on the rug. I mean taint as in the anatomical area beween the anus and the testicles. And it was a taint that hadn't been washed in years.

Later on, after this first group of developers deserted another one joined. His idea was to make a DinkC++ language out of a parser and a lexer – a true language. He was able to recruit another developer who became our graphics programmer. After weeks of development, he disappeared and was never seen again. I think he died. Maybe he got hit by a car? Anyway, shortly after, the first developer disappeared. I am unsure of his current situation but I understand he lives in Australia. You all know what can happen there. He might've eaten Vegimite.

I am not writing this to tell of people who deserted me. If I was I could write a book. And I could keep writing for the rest of my life. And writing...and writing...people will hate me for that is their nature. But like I said, I am not writing this to tell of people who deserted me. I'm not even sure WHY I'm writing this. Anymore, anyway.

Windemere, in its current state, is...something. I don't even know. At the current rate of development (which will most likely decrease logarithmically) progress will be completed very early next year. Or maybe at the end of this year if I'm lucky. That said, take it with a grain of salt. Previously I had a chart on the website that stated various stages of development that were complete and those which needed to be completed along with estimated completion dates. I will not be doing that this time. I disappointed people after I was unable to make several release dates.

Maybe that's why people hate me?

So, I after I started rewriting the engine it became clear that I would need to quickly remove the previous stumbling block – the scripting engine. DUN DUN DUN. I tried using flex and bison to make a customized version but one thing became clear fast: I would never be able to make a decent language in the time alloted (i.e. Before I got bored and gave up). On my travels across the Interweb one day on my routine Google search for “[expletive deleted]” I came across the scripting language called “Lua”, Portuguese for “moon”. It had most of the things I wanted and it was better than I could have done. Which makes sense considering it was made over a period of years. YEARS.

I used this language as the basis for a new language that I dubbed DinkC++. It basically is Lua, but it has a few syntactical differences.

Let's take a look at the language.

Example 1:

function main()
....local v = 2;

....if(v == 2)
........v = 3;
....end

....return v;
end

As you can see it is very similar to Seth's tainted DinkC, with a few notable differences.

First, the most obvious one, there are no braces. But why? It looks less like C and is less intimidating to the new user.

Second, variables are defined typeless. This means that v could, in theory, be given several different types without consequence:

local v = 2;
v = “I am a string”;

That is perfectly valid. This is where you need to be careful, however. Global variables in the engine are integer-based, meaning that if your script assigns a string value to one of them your script will come to a grinding halt. The engine will still run, but weird things may happen depending on what you were scripting for.

Nextly, the language can do complex math like 2 + 4 + 42. And variables no longer have to be prefixed with the annoying-as-hell ampersand (&) character. Also, you can assign variable names 'variable1' and 'variable2' without them cross referencing each other. Wow.

The most obvious thing here is probably the return value. Yes, you can write your own functions now!

function GetAvg(x, y)
....return (x + y) / 2;
end

function main()
....local q = 1;
....local z = GetAvg(q, 3); // Z will equal 2.
end

Now wasn't that cool?

Just a couple spiffy other things: There is no limit to the amount of global variables one can have. One can also define a global right in the middle of his or her function by using MakeGlobal(variable_name) function. So:

function main()
....local x = 4;

....if(x < 5)
........MakeGlobal(“glb”);
........glb = 0;
....end
end

It is recommended to put your global definitions in the main.dpp file so you always know what they are, however. But it IS possible.

One final reminder: semicolons are optional. I'm just used to programming in C++ so I like them. But you might not.

I do hate preps though.

I will continue to write these article things as long as somebody reads them. My apologies if you could follow my logic.

So tell me, did I answer your question? Huh? HUH?
November 15th 2004, 08:55 PM
girl.gif
joshriot
Peasant They/Them United States
keep it real 
do you expect me to read all that
November 15th 2004, 08:58 PM
wizardb.gif
Merlin
Peasant He/Him
 
I do if you plan to develop for Windemere.
November 15th 2004, 09:30 PM
pq_frog.gif
Ric
Peasant They/Them Canada
 
Hey, its worth the read.
Its easier.
Betcha its stable..
And I bet that description of Seths' code gets quoted.
November 15th 2004, 10:51 PM
wizard.gif
Chrispy
Peasant He/Him Canada
I'm a man, but I can change, if I have to.I guess. 
That's all interesting and such, but what are you doing on saturday? ;p
November 15th 2004, 10:52 PM
wizardb.gif
Merlin
Peasant He/Him
 
OMG I FEEL SO LOVED!!

Actually, nothing. I never do anything on Saturday. Can you tell?
November 15th 2004, 10:57 PM
farmer.gif
+whistles+ hiiiii.
November 15th 2004, 11:43 PM
wizardb.gif
Merlin
Peasant He/Him
 
Update: Math support has been added. These now work:

abs(n)
-- Returns absolute value of n.

sin(n)
-- Returns sine of n.

cos(n)
-- Returns cosine of n.

tan(n)
-- Returns tangent of n.

asin(n)
-- Returns arcsine (sin ^ -1) of n.

acos(n)
-- Returns arccosine (cos ^ -1) of n.

atan(n)
-- Returns arctangent (tan ^ -1) of n.

atan2(y, x)
-- Returns arctangent of y/x. Returns the angle of the bidimensional vector (x, y).

ceil(x)
-- Returns smallest integer greater than or equal to x.

floor(x)
-- Returns the largest integer less than or equal to x.

mod(x, y)
-- Find the modulus between x and y (Remainder of floating-point division).

frexp(x, y)
-- Gets the mantissa and exponent of a floating-point value.

ldexp(x, y)
-- Gets the floating-point value from a mantissa and an exponent

sqrt(x)
-- Finds the square root of x

min(x, ...)
-- Finds the lowest in a series of numbers.

max(x, ...)
-- Finds the greatest in a series of numbers.

log(x)
-- Finds the natural logarithm of x.

log10(x)
-- Finds the common logarithm of x (I love logarithms).

exp(x)
-- Returns the exponential of x (I hate exponentials).

deg(x)
-- Converts x (in radians) to degrees.

pow(x, y)
-- Raises x to the y power. Also works with the ^ symbol.

rad(x)
-- Converts x (in degrees) to radians.

random()
-- Picks a random number.

randomseed(x)
-- Re-randomizes the random seed.

For example:

function main()
....Log(math.pi);
....Log(math.sin(math.pi));
end

Returns to STDIO (The Log function without the math. prefix sends it to the log file):

Windemere inkC++: 3.1415926535898
Windemere inkC++: 1.2246063538224e-16
November 15th 2004, 11:44 PM
burntree.gif
Striker
Noble She/Her United States
Daniel, there are clowns. 
Ah, Lua... I've scripted in Lua, it was quite good.

Missing release dates has nothing to do with people hating you. If it's going to be anything, it be your own jerk-ass personality.
November 16th 2004, 07:54 AM
pq_skull.gif
Drake
Peasant He/Him
 
Holly shat bats! Complex math and geometry! Sweet Now we can make better projectiles and numerous other things.

EDIT: So, what are you doing saturday

Oh NVM you and VaultDweller...
November 16th 2004, 08:29 AM
fish.gif
Simeon
Peasant He/Him Netherlands
Any fool can use a computer. Many do. 
Yeah, I read it all - looks promising

Btw:

log(x)
-- Finds the natural logarithm of x.

Isn't that ln(x) or should we remember the fact that the language works with log and log10?
November 16th 2004, 12:51 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Beh, the real mathematicians "log" is the "ln". I write "log" every time when I mean what you call "ln". In all other cases it'd be "nlog" with n superscript (these cases are rare).

Oh, and the sine, cosine, tangent etc. use radians, right?
November 16th 2004, 04:37 PM
wizardb.gif
Merlin
Peasant He/Him
 
All of the above functions use radians (except the rad(x) and the random functions, of course).

And it doesn't really matter if you use log() or ln(). You'll still get the same answer (Just don't forget to convert to base 10 if you just want to use log10).
November 17th 2004, 01:49 AM
boncap.gif
as
Peasant He/Him India
 
you sound like my math teacher
November 17th 2004, 07:40 AM
fish.gif
Simeon
Peasant He/Him Netherlands
Any fool can use a computer. Many do. 
And it doesn't really matter if you use log() or ln()

you sound like my math teacher

My math teacher would just say that log uses base 10 and ln uses base e
November 17th 2004, 04:26 PM
wizardb.gif
Merlin
Peasant He/Him
 
I'd get a new math teacher.
November 17th 2004, 05:43 PM
wizard.gif
Chrispy
Peasant He/Him Canada
I'm a man, but I can change, if I have to.I guess. 
Bah. My calculus teacher said trig had nothing to do with calculus. Oh and proofs? Schmoofs!
November 17th 2004, 06:59 PM
wizardb.gif
Merlin
Peasant He/Him
 
Trig is one of the fundamental things in Calculus. Most of the functions in calculus require an understanding of those trig functions (mainly when you get a problem based on the unit circle). A lot of integral calculus will have trig problems in them and that understanding will make it much easier to solve them (because most can be simplified).
November 18th 2004, 07:29 AM
wizard.gif
Chrispy
Peasant He/Him Canada
I'm a man, but I can change, if I have to.I guess. 
And that explains why I'm having so much bloody trouble with calc now.
November 18th 2004, 12:54 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
I second that. Try to Integrate 2*sqrt(R^2-x^2) without trig. You'd never come to pi*R^2. Or maybe, you will, but it could be done much faster.

Took me a while to find the correct substitution...
November 18th 2004, 06:38 PM
pq_frog.gif
Ric
Peasant They/Them Canada
 
This whole conversation tells me I should have gone further in school
I get this, but not well enough to apply it.