Skip to content

Instantly share code, notes, and snippets.

@uliwitness
uliwitness / cppwrapper.cpp
Created October 21, 2015 00:16
Wrapping C++ in Swift via a C wrapper.
#include "cppwrapper.h"
#include "buff.hpp"
extern "C" void buff_deinit( buff* _this )
{
delete _this;
}
extern "C" buff* buff_init( int type, double amount, double max_amount, double start_angle, double relative_angle, double max_distance, double bleedthrough, bool permanent )
{
@uliwitness
uliwitness / cardflipper.hc
Last active November 21, 2015 15:33
How to flip through cards in HyperCard.
-- first approach:
-- sadly this causes a deep nested hierarchy where "go" calls "openCard"
-- which calls "go", eventually running out of memory.
on openCard
wait 5 seconds
go next
end openCard
-- second approach:
-- idle gets called periodically by HyperCard, but you don't have control over
You can specify the underlying name for a C function the linker/compiler should actually use. If you use an existing
function's name, it will just let you refer to it with your prototype's name. If you define the function, it'll give
it that name. It even complains if a function of that name already exists. Tested with clang on a Mac, but AFAIK also
works in GCC. You can even use special characters in your function names, like you can do in assembly.
@uliwitness
uliwitness / gist:5330743
Last active December 15, 2015 22:09
Macro-based implementation of objects as constants for Objective C. Could probably write code that auto-generates all the OCONSTANTI(a) macro calls based on the OCONSTANT(a) macros. But that wouldn't work for system headers.
#import <Foundation/Foundation.h>
#define PASTE(a,b) a ## b
#define OCONSTANT(a) @class a; extern a* PASTE(k,a); @interface a : NSObject @end
#define OCONSTANTI(a) @class a; a* PASTE(k,a) = nil; @implementation a +(void) load { PASTE(k,a) = [[a alloc] init]; } @end
#import <Foundation/Foundation.h>
#include <iostream>
@interface ULIFoo : NSObject
@end
@implementation ULIFoo
-(id) init
@uliwitness
uliwitness / gist:8043486
Last active December 31, 2015 20:59
Looks like the 10.9 SDK breaks code like the following. Anyone know how I can fix that w/o moving the function out of the class? Works fine with the 10.8 SDK.
namespace Carlson
{
class CToken
{
public:
static void GoNextToken( const char* fname, std::deque<CToken>::iterator& tokenItty, std::deque<CToken>& tokens );
};
}
struct eat_char_fcn
{
eat_char_fcn( struct eat_char_fcn (*inFun)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) ) : function(inFun) {}
struct eat_char_fcn operator()( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att ) { return function(currCh,reader,nod,att); }
explicit operator bool() { return function != nullptr; }
struct eat_char_fcn (*function)( char currCh, xml_reader& reader, vector<shared_ptr<node>>& nod, attribute* att );
};
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
int* __nullable foo = NULL;
int& fooRef = *foo;
}
return 0;
}
<html>
<head>
<title>Streaming - Back Soon</title>
</head>
<body bgcolor="#00ff00">
<div id="message" style="font-size: 80pt; font-family: Helvetica; font-weight: bold; color: white; text-shadow: 2px 2px #000000;">
Back in <span id="timer">5:00</span> minutes
</div>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="AppleScriptPropertyTest Terminology" xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="file://localhost/System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
<suite name="AppleScriptPropertyTest Suite" code="ASPT" description="AppleScriptPropertyTest Suite">
<cocoa name="ULIAppleScriptPropertyTestSuite"/>
<class-extension description="The App" extends="application">
<cocoa class="NSApplication"/>
<property name="boogaloo" code="ACTV" description="App&apos;s boogaloo prop." type="boolean">