• Advertisement
Sign in to follow this  
  • entries
    557
  • comments
    1237
  • views
    422690

Woo, DruinkScript

Sign in to follow this  

235 views

I played about with GameMonkey script, and then discovered that it kept crashing (deleting an invalid pointer for some reason), so I gave up with it and decided to make my own scripting language; DruinkScript.
It's very simple and assembly like. Here's my test script:

; for(int a=0; a<10; ++a) Test();
mov a, 0 ; a=0
mov b, 10 ; b=10
label omgwtflol2
call Test
inc a
cmp a, b ; if(a < 10)
jl omgwtflol2 ; goto omgwtflol2;

; for(int a=0; a<10; ++a) Test();
mov a, 0 ; a=0
label omgwtflol2
call Test
inc a
cmp a, b ; if(a < 10)
jl omgwtflol2 ; goto omgwtflol2;


All working [smile] The main reason I did this is so I know exactly what's going on internally when I call scripts, and so I can say I've written a scripting language :P

Anyway, I'm knackered, and it's 4:40am here, so I'm going to leave this as a short entry.
Sign in to follow this  


3 Comments


Recommended Comments

Oh yeah, I don't disagree that it's ugly [smile] But it was fast to write, very fast to run, and very difficult to crash. So it suits my needs perfectly.

And here's some sample code:

bool Callback(IDruinkScriptStack* pStack, IDruinkScriptVM* pVM, void* pContext)
{
// Check the top of the stack is a string
if(pStack->GetTop()->type != IDruinkScriptStack::Type_String)
{
pVM->SetError("Function() expects a string argument");
return false;
}

OutputDebugString(pStack->GetTop()->val.sz);
pStack->Pop();
return true;
}

const char* szScript =
"push \"Hello World! \n"
"push 42\n"
"add\n" // Composes "Hello World! 42" on the stack
"push \"\n"
"add\n"
"call Function\n";

IDruinkScriptVM* pVM = CreateDruinkScriptVM();

// The VM ensures that the stack has at least the 3rd parameter
// elements on it, so you don't need to check in the function.
pVM->BindFunction("Function",Callback,1,NULL);

IDruinkScript* pScript =
pVM->CompileScript(szScript,"Scriptname");
if(!pScript) return false;
pScript->Run();



Huzzah!

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement