Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile
@nilium
nilium / gist:79287
Created March 15, 2009 03:12
Alternate method of handling exceptions in TMonoMethod.Invoke
Rem
bbdoc: Invoke the method. If an exception is passed, its internal pointer must be Null.
returns: A mono object containing the return data, or Null if an exception is thrown.
End Rem
Method Invoke:TMonoObject(obj:TMonoObject, params:Byte Ptr[], exception:TMonoObject)
Return InvokeByPointer(obj._pointer, params, exception)
End Method
Rem
@nilium
nilium / lua_test.bmx
Created March 16, 2009 02:54
Example of calling Lua functions and Lua calling C functions in BlitzMax
' lua_test.bmx
Strict
Import Axe.Lua
' Available to lua
Function lua_KeyHit( lvm@ Ptr )
' Get the number of arguments to the function
@nilium
nilium / test.bmx
Created March 16, 2009 23:21
Example of Lua reflection code
' test.bmx
Type Foo {expose}
Method Bazzle( obj:Bar )
If obj = Null Then
Print "Null obj"
Else
Print obj.ToString()
EndIf
IDENTIFIER_REGEX=/[a-zA-Z_]\w*/
TYPENAME_REGEX=/(?ix)
# type shortcut
(?:
( [!#%] | @{1,2} | \$[zw]? )
|
: \s* ([a-zA-Z_]\w*)
)
# pointer
@nilium
nilium / regexps.rb
Created March 21, 2009 08:03
Regular expressions used in the BBDocugen documentation generator for BlitzMax
# BBDocugen - BlitzMax Documentation Generator
# Copyright (C) 2009 Noel Cower
#
# BBDocugen is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BBDocugen is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
// ignore this, just include bits as usual
#import <list>
#import <stdint.h>
// this is just an example class, don't read too much into it
class Object
{
private:
uint32_t m_refs;
#include <stdio.h>
#include "test.h"
int main(int argc, char ** argv)
{
int i = globalVariable;
globalVariable = 50;
Last login: Tue Apr 7 02:56:43 on ttys002
/Users/noel/Source/Misc/bmax/lua-reflection/test ; exit;
[noel@Ouroboros ~]$ /Users/noel/Source/Misc/bmax/lua-reflection/test ; exit;
~>Unhandled Exception:Not handling this shit
~>
t
~>StackTrace{
~>@/Users/noel/Source/Misc/bmax/lua-reflection/test.bmx<26,1>
~>Function test
~>Global Running:Int=1
SuperStrict
Function Script_Require:Int( lvm:Byte Ptr )
Local fname:String
While lua_gettop(lvm) > 0
fname = lua_tostring(lvm, -1)
lua_settop(lvm, -2)
If Not fname Then Throw "Invalid argument to require - nil"
If FileType(fname) <> FILETYPE_FILE Then Throw "Script ~q"+fname+"~q does not exist"
If lual_dofile(lvm, fname) Then Throw "Error executing script ~q"+fname+"~q: "+lua_tostring(lvm, -1)
Function script_binor:Int(lvm:Byte Ptr)
Local result:Int = 0
While lua_gettop(lvm)
result :| lua_tointeger(lvm, -1)
lua_settop(lvm,-2)
Wend
lua_pushinteger(lvm, result)
Return 1
End Function