Esempio n. 1
0
int main() {
	int arr[] = {
		1, 2, 3, 4, 5, 6, 7
	};
	int i = 0, *top = 0;
	Stack stack;
	StackInit(&stack, sizeof(int));

	while (i < sizeof(arr) / sizeof(int)) {
		StackPush(&stack, &arr[i]);
		++i;
	}

	top = StackTop(&stack);
	printf("The top of the stack element is %d\n", *top);
	top = StackPop(&stack);
	printf("Pop element  %d\n", *top);
	top = StackTop(&stack);
	printf("The top of the stack element is %d\n", *top);

	printf("The stack size is %d\n", StackSize(&stack));

	StackClear(&stack);
	if (StackEmpty(&stack)) {
		printf("Stack is empty.\n");
	} else {
		printf("Stack is not empty.\n");
	}
	StackDestory(&stack);
	return 0;
}
Esempio n. 2
0
		LuaRef registerClass(lua_State* state)const
		{
			util::ScopedSavedStack save(state);
			if (class_userdata::newmetatable<class_type>(state))
			{
				LuaTable metatable(state, StackTop());
				metatable.push();
				registerMember(state);

				if (!traits::is_same<base_class_type, void>::value || !property_map_.empty())//if base class has property and derived class hasnt property. need property access metamethod
				{
					for (PropMapType::const_iterator it = property_map_.begin(); it != property_map_.end(); ++it)
					{
						int count = lua_type_traits<FunctorType>::push(state, it->second);
						if (count > 1)
						{
							lua_pop(state, count - 1);
							count = 1;
						}
						if (count == 1)
						{
							lua_setfield(state, -2, ("_prop_" + it->first).c_str());
						}
					}
					LuaFunction indexfun = kaguya::LuaFunction::loadstring(state, "local arg = {...};local metatable = arg[1];"
						"return function(table, index)"
//						" if type(table) == 'userdata' then "
						" local propfun = metatable['_prop_'..index];"
						" if propfun then return propfun(table) end "
//						" end "
						" return metatable[index]"
						" end")(metatable);

					metatable.setField("__index", indexfun);

					LuaFunction newindexfn = LuaFunction::loadstring(state, "local arg = {...};local metatable = arg[1];"
						" return function(table, index, value) "
						" if type(table) == 'userdata' then "
						" local propfun = metatable['_prop_'..index];"
						" if propfun then return propfun(table,value) end "
						" end "
						" rawset(table,index,value) "
						" end")(metatable);
					metatable.setField("__newindex", newindexfn);
				}
				else
				{
					metatable.setField("__index", metatable);
				}

				set_base_metatable(state, metatable, types::typetag<base_class_type>());

				return metatable;
			}
			else
			{
				except::OtherError(state, typeid(class_type*).name() + std::string(" is already registered"));
			}
			return LuaRef(state);
		}
Esempio n. 3
0
int main(void) {
Stack s;
StackEntry e;

CreateStack(&s); //for intializing the stack

if (!StackFull(&s))
    Push (e, &s);

if (!StackEmpty(&s))
	Pop (&e, &s);

if (!StackEmpty(&s))
	StackTop (&e, &s);

x = StackSize (&s);

ClearStack (&s);

return 0;

}
Esempio n. 4
0
		static LuaThread get(lua_State* l, int index)
		{
			lua_pushvalue(l, index);
			return LuaThread(l, StackTop());
		}
Esempio n. 5
0
		static LuaFunction get(lua_State* l, int index)
		{
			lua_pushvalue(l, index);
			return LuaFunction(l, StackTop());
		}