Jump to content

  • Log In with Google      Sign In   
  • Create Account


AzureBlaze

Member Since 27 Apr 2011
Online Last Active Today, 07:25 PM
-----

Posts I've Made

In Topic: LUA load file into table

08 May 2014 - 07:40 AM

If you are using Lua 5.1 you can use setfenv to alter the global table the function will be run in.

loadedScript = {}
f = loadfile("myscript.lua")   --use loadfile to load the script but don't execute it yet
setfenv(f,loadedScript)
f()

You might also want to redirect lookups to the original global table so you can use io.write in loadedScript

 

There should be something similar in Lua 5.2(setfenv() was removed) but I'm not familiar with it.

mt = {
__index = _G   -- if we can't find something in loadedScript, try global table instead
}
setmetatable(loadedScript,mt)

In Topic: Inline for clone() function

11 April 2014 - 10:02 PM

inline still have its' uses. Just not much for optimization

 

Consider if you are writing a header only library:

#pragma once
class bar;

class foo{
public:
	foo();
	bar *b;
};

class bar{
public:
	bar(foo *_f):
		f(f)
	{
	}
	foo *f;
};

inline foo::foo()
	:b(new bar(this))
{}


inline on foo::foo() is mandatory. it ensures the compiler and liker that no matter how many times it see the definition of foo::foo(), it will refer to a completely same function. Remove inline and you'll get a linker error because of multiple definitions.


In Topic: DRM protection

11 April 2014 - 11:41 AM

Story: Back when I was in college we have a legit 500 user license for some expensive CAD software (donated, I think for tax reasons). But we, including the computer room, all use a cracked version which is given by the dealer. Setting up and maintaining a key server is simply too much trouble.

 

Some DRM cause so much trouble even legal users have to use cracked ones.


In Topic: Documenting scripting language in application

06 April 2014 - 12:12 AM

I was searching for something similar, but my final solution write a documented header for Doxygen to parse. Doxygen is quite forgiving about grammar rules such as missing return type for functions so I think it should work with most scripts by writing the document similar to c++ style.

 

for example:

#ifdef LUA_TABLE
//! Provides generic functions for table manipulation.
class table{
	
	//! Given an array where all elements are strings or numbers, returns table[i]..sep..table[i+1] ... sep..table[j].
	static concat (table [, sep [, i [, j]]]);

	//! Inserts element value at position pos in table, shifting up other elements to open space, if necessary.
	static insert (table, [pos,] value);

	//! Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.
	static maxn (table);

	//! Removes from table the element at position pos, shifting down other elements to close the space, if necessary.
	static remove (table [, pos]);

	//!Sorts table elements in a given order, in-place, from table[1] to table[n], where n is the length of the table.
	static sort (table [, comp]);

};
#endif

results in:

Hk1XAGA.png

 

 

I also use the generated XML for autocomplete in my script editor

iI8sY1Z.png


In Topic: 0..99 or 0..100

16 March 2014 - 08:49 PM

In my humble opinion the only sane way to draw a line is a function that takes a laser pointer and a unicorn. People who don't do it in MY way is silly, illogical and wrong and should all destruct in Turing's hell.

 

There is no right and wrong here, just matters of personal preference. It is done so because it is done so in the last few decades. people are used to this way and there are nearly no big enough incentives to change.

 

Also I only use drawline for debbuging. I simply don't care if the last pixel is drawn or not. I iterate through the edges and get a closed polygon, I'm happy enough with that.

 

Your opinion here is not going to change anything. Live with it, write your own engine, try to get a position in OpenGL or DirectX and let people hate you because you break their existing code.

 

Or wrap it up with a adapter funciton:

void SparkleDrawLine(Laser *laser, Unicorn &unicorn){
    DrawLine((int)laser & 0xffff,(int)laser >>16, unicorn.GetRainbowTurd().size , unicorn.GetRainbowTurd().weight);
}

PARTNERS